none
Outlook 2007/2010 - Need to turn ItemChange firing off and turn it on back RRS feed

  • Question

  • I'm writing a VSTO plugin for Outlook that tracks new appointment creation via ItemAdd event. In this handler I have to change the item's properties along with the properties in some other appointments as well. But all that code leads to ItemChange firing which I want to be temporarily turned off until my changes are done. After that moment I want to turn tracking of ItemChange back. How can I do this? 
    Monday, June 11, 2012 11:16 AM

Answers

  • you could keep only last 50 added entries and remove excess ones on adding new one. As for ItemChange re-entrancy issues - set a flag that you are currently in item change processing and clear it on exit, sonething like this:

    bool processing = false;

    function void ItemChange(Object item)

    {

    if(processing) return;

    try

    {

    processing = true;

    }

    finally

    {

    processing = false;

    }

    }

    Tuesday, June 12, 2012 8:49 AM

All replies

  • turn off events for all add-ins etc.? impossible. If you however mean only to turn it off for your code only - either set flag which you will check in itemchange event hnadler to not process that event or unsubscribe from event and subscribe again at the end of your item add handler.
    Monday, June 11, 2012 11:41 AM
  •  subscribe again at the end of your item add handler.
    The problem is that these ItemChange calls occur far after the moment I leave the ItemAdd handler. I need a way to determine if adding was completed to track this moment and this is not quite clear for me.
    Monday, June 11, 2012 3:35 PM
  • itemchange fires wherever outlook pleases so what exactly are you trying to determine inside item change event to determine course of action?

    Monday, June 11, 2012 5:45 PM
  • You can store the list of processed items's entry ids in a string list and check if the item was already processed by ItemAdd when ItemChange fires.

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

    Monday, June 11, 2012 5:54 PM
  • ok, but when to clear this list? Don't think it's a good idea to have a constantly growing list. In addidtion to that, I may change the same item many times and I need to have these changes reflected and processed as well. The only ItemChange I want to suppress are calls initiated from ItemAdd or another ItemChnage.
    Tuesday, June 12, 2012 7:57 AM
  • you could keep only last 50 added entries and remove excess ones on adding new one. As for ItemChange re-entrancy issues - set a flag that you are currently in item change processing and clear it on exit, sonething like this:

    bool processing = false;

    function void ItemChange(Object item)

    {

    if(processing) return;

    try

    {

    processing = true;

    }

    finally

    {

    processing = false;

    }

    }

    Tuesday, June 12, 2012 8:49 AM
  • Do you always change the items? After you process a message, what changes? When your code looks at the message for the second time, can't you tell that the changes have alreday been made and tehre is no reason to proces it again? If not, can you mark the message with a user property that will tell your code to skip it next time?


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

    Wednesday, June 13, 2012 7:13 AM