• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Event Handler Problem

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
  • 2
  • 2
1 Solution
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.
javapossumAuthor Commented:
To chuang4630" How do I transfer this question to the area you suggested?
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.

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.
javapossumAuthor Commented:
Thanks very much for your answer Mike, this is exactly what is causing it :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now