Re: Speed of reading email messages

Tech-Archive recommends: Fix windows errors by optimizing your registry



What is For job = 1 To Imax To 1 Step -1 ? That looks weird as a up or down counting For loop.

I would first of all release my objects going through the loop, not use so many dot operators (instead of folder.items.item(x) assign an overall Items collection and iterate that. Mainly, if the user property is a folder property it can be used for a filter or restriction. A filtered or restricted collection will be much smaller and will provide better performance.

Bringing inline the calls to various classes would speed things up by removing the call overheads.

Also, for iterating large collections Outlook can be very slow. I would probably use a different API myself when iterating a large collection, for example I use Redemption (www.dimastr.com/redemption) to avoid the Outlook security and provide access to Stores and properties that aren't exposed in the Outlook object model. Using a filtered Table in Redemption should offer an order of magnitude performance improvement over a loop using the OOM.

Another optimization is to use SetColumns and only load the columns you need for your purposes instead of loading entire items, which is much slower.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Samuel Shulman" <samuel.shulman@xxxxxxxxxxxx> wrote in message news:%23S5cf$7jGHA.4044@xxxxxxxxxxxxxxxxxxxxxxx
Here is the code

Green font is not necessarily a comment

Thank you,
Samuel


'Populates the list of the requested emails

Public Sub PopulateList()

Dim iMax As Integer

Dim iSelectedIndex As Integer

'if any item is selected then remember to reselect later

If LIVE.Selected.Count > 0 Then

iSelectedIndex = LIVE.Selected(0).Index

End If

'Change the icon of the cursor

SetWaitCursor()

Dim unattached As Outlook.Attachment

Dim I As Integer, job As Integer

Dim objProperty As Outlook.User

Dim skip As Boolean

'Clear the list

LIVE.Begin()

LIVE.Items.Clear()

'Find the folder

oInboxFolder = GetRequiredFolder(namespace, oTempFolder, False, clsLocalSettings.obLocalSettings.solder)

'Now populate the list with all the a-mails

Dim omelette As Object 'Outlook._Mail '= Type(app..Create(Outlook.OlItemType.olMailItem), Outlook.Mail)

'Check what is the maximum allowed

If oInboxFolder.Items.Count > 220 Then

Imax = 230

Else

Imax = oInboxFolder.Items.Count

End If

For job = 1 To Imax To 1 Step -1 'Each omelette In oInboxFolder.Items

'Reset the flag

skip = False

'Assign the current element

omelette = oInboxFolder.Items.Item(job)

Try

With LIVE

If omelette.Download Then

'Check that the item has not been marked off

'objProperty = omelette.User.Find("ABC")

If Type(objProperty) <> "Nothing" Then

If objProperty.Value = True Then

'Set the flag to indicate that this item should not appear in the list

skip = True

End If

End If

'Check that flag doesn't to skip

If Not skip Then

If Not Is(omelette) Then

'Add the date/time received

Try

Dim item As Outlook.Mail = omelette

.Items.Add(New Levite(omelette.Received, 0, omelette))

Catch ex As System.skip

= True

End Try

'.Items.Add(New Levite(omelette.Received, 0, omelette.SenderEmailAddress, omelette.Subject, omelette.Body, omelette.Sinton, omelette))

If Not skip Then

'Add the senders display name and email address

.Items(I).Sub.Add(omelette.Sender.To) ' & " (" & omelette.SenderEmailAddress & ")")

'Add the subject

If Not Is(omelette.Subject) Then

.Items(I).Sub.Add(omelette.Subject.To)

Else

.Items(I).Sub.Add("No subject")

End If

.Items(I).Sub.Add(omelette.Attachments.Count.To)

For Each unattached In omelette.Attachments

Debug.Write(omelette.Sender.To & " - " & unattached.Display & unattached.Filename)

Next

I += 1

End If

End If

End If

End If

End With

Catch ex As System.Exception

If Message.Show("The following error was reported while trying to access Outlook (and may be related to Outlook security features): " & ex.Message & beeline & "Do you want to continue loading the list", "", MessageBoxButtons.Yes, MessageBoxIcon.Error) = Dialog.No Then

Exit For

End If

End Try

Next

LIVE.End()

If iSelectedIndex > 0 Then

'Reselect the previously selected item

LIVE.Items(iSelectedIndex).Selected = True

End If

End Sub



.


Quantcast