Event Handler Problem

Posted on 2006-05-15
Last Modified: 2013-11-12
The code snippet below works fine when Microsoft Outlook is NOT running.
IE: MS Word opens the .doc file OK and the close event fires OK when MS Word is closed.

However when MS Outlook (email client) is running in the background, NO events are fired when MS Word is closed.

(I have Microsoft Office 2003 installed)

Does anybody have any ideas as to what is causing the code to fail?
process = new Process();
ProcessStartInfo processStartInfo= new ProcessStartInfo("C:\temp.doc");
processStartInfo.Verb = "Open";
processStartInfo.CreateNoWindow = false;
process.StartInfo = processStartInfo;

process.Exited += new System.EventHandler(process_Exited);
process.EnableRaisingEvents = true;  // Events fire when MS Word closes

private void process_Exited(object sender, System.EventArgs e)
 // do something
Question by:javapossum
    LVL 1

    Expert Comment

    This question is more appropriate to be posted in the App/MS Office area, in my opinion.

    The code itself looks fine to me. The issue seems to be Office 2003 specific.

    Author Comment

    To chuang4630" How do I transfer this question to the area you suggested?
    LVL 3

    Expert Comment

    Do you have "Use Microsoft Word to edit e-mail settings" selected in your Outlook options?

    If you do then Outlook runs a copy of WinWord in the background. Look in task manager and see if winword.exe is listed when you have outlook running. This process will remain running whilst Outlook is running regardless of how many word docs you open or close. Although you have multiple documents open, there is only even one instance of winword.exe and until you close everything that is using winword (including Outlook), it's process won't terminate.

    So, to answer youe question, you don't get an event because the winword.exe process has not existed because it's in use by Outlook.

    LVL 3

    Accepted Solution

    Sorry, I was having a figure trouble in my last paragraph... it should read:

    So, to answer your question, you don't get an event because the winword.exe process has not exited because it's in use by Outlook.

    Author Comment

    Thanks very much for your answer Mike, this is exactly what is causing it :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now