none
Outlook shows extra save-confirmation-dialogs when closing the app after cancelling Send RRS feed

  • Question

  • Hello,

    I have to call mailItem.Save when the mailItem is sent, to save some properties.

    I also have some UI popping up after user clicks on Send, allowing the user to Cancel the send.

    If the mailItem was dirty before I called mailItem.Save(...) , I need to make it dirty again, so that if user has cacelled "Send" from my UI, and close the inspector window, they should see the Save confirmation message.

    Now when I make the mailItem dirty, after calling mailItem.Save, and cancel the "Send", on closing the inspector window, I do get a confirmation message box as expected. The problem is, if I close the Outlook Application Window after that, I get 2 more confirmation dialogs, which is not correct, and is confusing for user.

    Below is a piece of C# code that causes this behaviour:

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.ItemSend +=Application_ItemSend;
            }

            private void Application_ItemSend(object Item, ref bool Cancel)
            {
                Outlook.MailItem mailItem = Item as Outlook.MailItem;

                // Change some properties ...

                ....

                mailItem.Save();            // Call Save so that properties are saved
                mailItem.Subject = "Hello World";   // Make it dirty again

                // Popup the UI

                ....

                Cancel = true;  // Assuming user pressed Cancel, hence cancelling the "Send"  
            }

    [ VS2012 - Outlook 2010 - VSTO Addin ]

    I am wondering if someone else has seen this behaviour and knows how to fix it? Or this is a known issue for Outlook Object Model?

    I would appreciate any help.

    Thanks & Regards,

    Muhammad.

    Tuesday, October 30, 2012 5:34 PM

Answers

  • Make sure to release all Outlook and other COM objects. You're instantiating a MailItem and not releasing it just in the snippet you showed. You should call Marshal.ReleaseComObject() or Marshal.FinalReleaseComObject() for each object and then set it to null.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "pNULL" <=?utf-8?B?cE5VTEw=?=> wrote in message news:e2d35780-da27-4d00-a09c-222c39d46a52...

    Hello,

    I have to call mailItem.Save when the mailItem is sent, to save some properties.

    I also have some UI popping up after user clicks on Send, allowing the user to Cancel the send.

    If the mailItem was dirty before I called mailItem.Save(...) , I need to make it dirty again, so that if user has cacelled "Send" from my UI, and close the inspector window, they should see the Save confirmation message.

    Now when I make the mailItem dirty, after calling mailItem.Save, and cancel the "Send", on closing the inspector window, I do get a confirmation message box as expected. The problem is, if I close the Outlook Application Window after that, I get 2 more confirmation dialogs, which is not correct, and is confusing for user.

    Below is a piece of C# code that causes this behaviour:

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.ItemSend +=Application_ItemSend;
            }

            private void Application_ItemSend(object Item, ref bool Cancel)
            {
                Outlook.MailItem mailItem = Item as Outlook.MailItem;

                // Change some properties ...

                .....

                mailItem.Save();            // Call Save so that properties are saved
                mailItem.Subject = "Hello World";   // Make it dirty again

                // Popup the UI

                .....

                Cancel = true;  // Assuming user pressed Cancel, hence cancelling the "Send"  
            }

    [ VS2012 - Outlook 2010 - VSTO Addin ]

    I am wondering if someone else has seen this behaviour and knows how to fix it? Or this is a known issue for Outlook Object Model?

    I would appreciate any help.

    Thanks & Regards,

    Muhammad.


    Ken Slovak MVP - Outlook
    Tuesday, October 30, 2012 6:50 PM
    Moderator