none
ItemEvents_10_AfterWriteEventHandler is triggers for all instances of the form region RRS feed

  • Question

  • Hello,

    I am using the following code in my form's FormRegionShowing to add a event handler to AfterWrite:

    ((Outlook.ItemEvents_10_Event)mailItem).AfterWrite += new Outlook.ItemEvents_10_AfterWriteEventHandler(CASLEmailFormRegion_AfterWrite);

    It is working; however, the event is being triggered for all instances of the formRegion. How do I limit it to the form that its save button has been just clicked?

    Thank you,

    Thursday, July 31, 2014 3:08 AM

Answers

  • It looks like the issue is related to your code, you shouldn't subscribe to the AfterWrite event in each form region instance. Instead, I'd suggest to choose a centralized place for such things, for example, see http://msdn.microsoft.com/en-us/library/office/ff973716(v=office.14).aspx .
    Thursday, July 31, 2014 12:43 PM

All replies

  • Hello,

    The AfterWrite event of the MailItem class is not related to form regions. Here is what MSDN states for the event:

    Occurs after Microsoft Outlook has saved the item.

    I.e. the event is fired for each item after Outlook has saved the item.

    Did you try to handle the event without form regions? Are you able to reproduce the issue without form regions?

    Thursday, July 31, 2014 9:49 AM
  • Hi Eugene,

    I am trying to handle the AfterWrite event of the MailItem in the form region code that displays the MailItem. Is that an acceptable practice or am I doing it wrong?

    >>the event is fired for each item after Outlook has saved the item.

    Yes, but it triggers the event handler in every single instance of the form region that is in memory.

    So I think either I am doing it wrong, or I need a mechanism that checks if the event is related to the form region that is showing the MailItem.

    Thank you for help.

    Thursday, July 31, 2014 12:35 PM
  • It looks like the issue is related to your code, you shouldn't subscribe to the AfterWrite event in each form region instance. Instead, I'd suggest to choose a centralized place for such things, for example, see http://msdn.microsoft.com/en-us/library/office/ff973716(v=office.14).aspx .
    Thursday, July 31, 2014 12:43 PM