none
About dispose() in outlook addins RRS feed

  • Question

  • Dear developers,

    I have an outlook addin 2007 app which runs very slow.

    I was wondering if I need to dispose all objects directly?

    In winforms I don’t since the form handles it but in outlook?

    I have the following objects:

    Local database.

    Datasets.

    And other classes that I import to my application, there I have public shared functions that execute SQL commands and return data tables (maybe here??)

    Tanks

    Patric

     

    Sunday, January 8, 2012 9:50 PM

Answers

  • Looks perfectly fine to me.

    Why would ItemChange event firing (asynchronously) be a problem?

    How many items do you process?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    • Marked as answer by Patrick12_3 Sunday, January 15, 2012 9:39 AM
    Wednesday, January 11, 2012 2:30 PM

All replies

  • What exactly is slow?

    Do you have a particular code snippet or an OOM calls that rausn slower than you woudl expect?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Monday, January 9, 2012 3:53 AM
  • Slow is when I iterate on all mail items and cast then

    Or when creating a new appointment.

     

         Dim app As Outlook.Application

         Dim ns As Outlook.NameSpace

         Dim folder As Outlook.MAPIFolder

     

     

         app = Globals.ThisAddIn.Application

         ns = app.Session

    folder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)

     

    for each(…..)

     

    Do I need to dispose app, ns and folder ?? Or wait for the garbage collector

     

     

    It is much slower since I added some public static shared functions In a different vb class

    And use them do I need to define a destructor to that class?

     

    Tanks

     

    Patric

    Monday, January 9, 2012 7:23 AM
  • Again, what exactly does your code do? Especially the "for each" loop?

    There are a quite few smart people on this forum, but none of them possess psychic abilities to the best of my knowledge.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Monday, January 9, 2012 7:38 AM
  • Dim WithEvents CalendarItemEvent As Outlook.Items
    
    Dim outlookNamespace As Outlook.NameSpace = Application.GetNamespace("MAPI")
    
    Dim calendar As Outlook.MAPIFolder = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
    
    CalendarItemEvent = calendar.Items
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    ''''Initial CalendarItemEvent when ever the user add or change new appointment 
    
    Dim Mylocation As String
    
    Mylocation = "some text.."
    
    Dim AllItems As Outlook.Items = calendarFolder.Items
    
    Dim Appintlist1 As New List(Of Outlook.AppointmentItem)
    
    Dim Appintlist2 As New List(Of Outlook.AppointmentItem)
    
    Dim obj As Object
    
    For Each obj In AllItems
    
    If TypeOf obj Is Outlook.AppointmentItem Then
    
    If obj.Location = Mylocation.ToString Then
    
    Appintlist1.Add(obj)
    
    Else
    
    Appintlist2.Add(obj)
    
    End If
    
    End If
    
    Next
    
    For Each Item In Appintlist1
    
    Item.Delete()
    
    Next
    
    For Each Item In Appintlist2
    
    Item.Location = Item.Location.ToString + "some comments"
    
    Item.Save() ' this is problematic because the appointment changed event is fierd
    
    Next
    

     

    • Edited by Patrick12_3 Monday, January 9, 2012 1:29 PM
    Monday, January 9, 2012 1:25 PM
  • Looks perfectly fine to me.

    Why would ItemChange event firing (asynchronously) be a problem?

    How many items do you process?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    • Marked as answer by Patrick12_3 Sunday, January 15, 2012 9:39 AM
    Wednesday, January 11, 2012 2:30 PM