none
Performance issue in searching through CalendarFolders for a particular appointmentid RRS feed

  • Question

  • I am searching myAppointmnetId  through calendarfolders to select the particular appointment from the user's calendarfolder and show it. This is taking more than a minute to open the particular appointment. Do we have any alternate solution for this?

     foreach (var Item in myAddin.myCalendarFolders.Items)
                    {
                        ApptItem = Item as Outlook.AppointmentItem;
                        if (ApptItem.GlobalAppointmentID == myAppointmentId)
                        {                                                             
                           ApptItem.Display(false);                      
                            Marshal.ReleaseComObject(ApptItem);
                            AItem = null;
                            Marshal.ReleaseComObject(Item);                                                                                                   
                            GC.Collect();
                            GC.Collect();                 
                            break;
                        }

                    }


    http://www.selvaonline.com - Live a Happy & Balanced Life

    Thursday, March 13, 2014 1:37 PM

Answers

  • You should not use foreach() loops and you shouldn't declare your objects inside the loop. Use a for loop and declare your objects outside the loop. That way you only create a few objects and you can re-use them in the loop.

    When you instantiate the item in the loop using a for() loop and its variable you don't take as much time as when you create a new item each time.

    You also may find that you don't have to call Marshal.ReleaseComObject on each loop pass. Often calling that every hundred or so loop passes is sufficient to not use up RPC channels. Calling the release code and the GC are expensive, so the fewer times you call them in your loop the faster your loop will run.


    Ken Slovak MVP - Outlook

    Thursday, March 13, 2014 2:06 PM
    Moderator

All replies

  • Normally, you could use Items.Find, but unfortunately the Outlook Object Model does not allow searching on the binary (PT_BINARY) MAPI properties.

    Extended MAPI (C++ or Delphi) or Redemption (any language) are your only options.

    In case of Redemption, the following VB script shows how to search for a given value of GlobalAppointmentID:

    strGlobalAppointmentId = Application.ActiveExplorer.Selection(1).GlobalAppointmentId
    
    set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
    set Folder = Session.GetRDOObjectFromOutlookObject(Application.ActiveExplorer.CurrentFolder)
    set Appt = Folder.Items.Find(" GlobalAppointmentID = '" & strGlobalAppointmentId & "' ")
    MsgBox Appt.Subject
    


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, March 13, 2014 1:58 PM
  • You should not use foreach() loops and you shouldn't declare your objects inside the loop. Use a for loop and declare your objects outside the loop. That way you only create a few objects and you can re-use them in the loop.

    When you instantiate the item in the loop using a for() loop and its variable you don't take as much time as when you create a new item each time.

    You also may find that you don't have to call Marshal.ReleaseComObject on each loop pass. Often calling that every hundred or so loop passes is sufficient to not use up RPC channels. Calling the release code and the GC are expensive, so the fewer times you call them in your loop the faster your loop will run.


    Ken Slovak MVP - Outlook

    Thursday, March 13, 2014 2:06 PM
    Moderator