Yanıt Getting close event of outlook.

  • 11 Haziran 2008 Çarşamba 10:19
     
     

    Hi

         I am writing a shared addin. I am using a thread in it. That thread runs infinite times. The problem which I am facing now is that even after closing the outlook the thread runs continuously. How can I get the Outlook close event so that I can stop the thread.

    I am using outlook 2007 and vs 2005.

    Thanks,
    Sanjay.

Tüm Yanıtlar

  • 13 Haziran 2008 Cuma 02:24
    Moderatör
     
     Yanıt

    Hi Sanjay,

     

    All threads will be terminated if its parent process runs over. The fact is that when clicking "X" option to close Outlook, the Explorer will be closed immediately, but Outlook Instance will remain for some time to do cleaning up work.

    I think you are justing trying to find event that will be fired when Explorer is closed, right?

    Try Explorer's Close event

    Code works in my side:

    Code Snippet

            Outlook.Explorer explorer = null;

     

                  public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)

                  {

                         applicationObject = application as Outlook.Application;

                         addInInstance = addInInst;

     

                explorer = applicationObject.ActiveExplorer();

                ((Outlook.ExplorerEvents_10_Event)explorer).Close += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_CloseEventHandler(Connect_Close);

                  }

     

            void Connect_Close()

            {

                MessageBox.Show("Terminate your thread here");

            }

     

     

    Thanks,

    Ji

  • 12 Nisan 2012 Perşembe 00:04
     
     

    Hello Ji

    I am new to C#. Can you please send me code to capture the outlook close event (Click on 'X'). I need to send message to application after outlook close event get triggered.

  • 12 Nisan 2012 Perşembe 07:39
     
     
    there is 'Quit' event on outlook's Application object.
  • 12 Nisan 2012 Perşembe 17:50
     
     

    Damian

    Thanks for prompt reply. Would you please send me sample code for the same.

     

  • 12 Nisan 2012 Perşembe 19:38
     
     

    in your main class for Addin, locate event handler for startup event (where you have code for initialization of your add-in) and add following lone there:

    Application.Quit += <your function for handling Quit event>

  • 13 Nisan 2012 Cuma 15:56
     
     

    Damian

    Below the code for outlook code event but it's not get triggered.

    OutlookApplication = app

    asoutlook.Application;

                    OutlookInspectors = OutlookApplication.Inspectors;

                   

                    OutlookInspectors.NewInspector +=

    newoutlook.InspectorsEvents_NewInspectorEventHandler(OutlookInspectors_NewInspector);

                    OutlookApplication.ItemSend +=

    newoutlook.ApplicationEvents_11_ItemSendEventHandler(OutlookApplication_ItemSend);

                   

    ((outlook.ItemEvents_10_Event)OutlookMailItem).Close += new outlook.ItemEvents_10_CloseEventHandler(CRMOutlook2010_Close);

    public

    voidCRMOutlook2010_Close(refboolCancel)

           {

              

    Console.WriteLine("Close Event");

               System.Windows.Forms.

    MessageBox.Show("Outlook Close!!!!");

               System.Windows.Forms.

    DialogResultResult1;

               Result1 = System.Windows.Forms.

    MessageBox.Show("Do you want to exit?", "Microsoft Outlook", System.Windows.Forms.MessageBoxButtons.YesNo);

              

    if(Result1 == System.Windows.Forms.DialogResult.Yes)

               {

                   Cancel =

    true;

                   OutlookMailItem.Display(

    true);

               }

              

    else


               {

                   Cancel =

    false;

                  

    if(string.IsNullOrEmpty(outputfiledetail))

                   {

                       filename =

    "outlmail.txt";

                       outputfiledetail = attachmentfilepath1 + filename;

                   }

                  

    stringCancelline1 = "\" OM \" ,  \"Cancel\"";

                  

    string[] Canceloutitem = { Cancelline1 };

                   System.IO.

    File.WriteAllLines(outputfiledetail, Canceloutitem);

               }

     

           }



  • 13 Nisan 2012 Cuma 18:32
     
     
    where in your code do you subscribe to Quit event on Application? i only see MailItem.Close event which is not the same.
  • 16 Nisan 2012 Pazartesi 17:33
     
     

    Damian

    C# code for  How to capture the outlook "X" click button event

  • 16 Nisan 2012 Pazartesi 17:57
     
     

    You can't trap that click, but you can handle the Quit() event, as Damian mentioned. To handle that event where _outlook is a class level Outlook.Application object you'd use code something like this:

    ((Outlook.ApplicationEvents_11_Event)_outlook).Quit += new Outlook.ApplicationEvents_11_QuitEventHandler(Outlook_Quit);

    private void Outlook_Quit()The Quit()event cannot be canceled.


    Ken Slovak MVP - Outlook

  • 16 Nisan 2012 Pazartesi 21:09
     
     

    Hi

    Please see my code below, the quit event didn't get trigered......?

    OutlookApplication = app

    asoutlook.Application;

                    OutlookInspectors = OutlookApplication.Inspectors;

                    OutlookInspectors.NewInspector +=

    newoutlook.InspectorsEvents_NewInspectorEventHandler(OutlookInspectors_NewInspector);

                    OutlookApplication.ItemSend +=

    newoutlook.ApplicationEvents_11_ItemSendEventHandler(OutlookApplication_ItemSend);

                    ((outlook.

    ApplicationEvents_11_Event)OutlookApplication).Quit += newoutlook.ApplicationEvents_11_QuitEventHandler(CRMOutlook2010_quit);

    publicvoidCRMOutlook2010_quit()

           {

               System.Windows.Forms.

    MessageBox.Show("Close Event Triggered");

              

    Console.WriteLine("Testing Outlook Event");

          

           }


  • 16 Nisan 2012 Pazartesi 21:18
     
     

    Where is the variable OutlookApplication declared? Is it at class level or somewhere where it could go out of scope and be garbage collected?

    You shouldn't use any sort of code in a quit event that could hang Outlook, such as modally displayed dialogs. Your addin will end up disabled by Outlook. Use Debug.WriteLine() if you're in debug mode, if not use an error log entry.


    Ken Slovak MVP - Outlook