The requirement is to detect closing of a word document opened by a process.
There is some piece of code which has to be executed after the document is
closed.
Using Process.Start() document is opened, I used process.WaitForExit() to
stop further execution until the document is closed.
But once the document is closed, Process.WaitForExit() throws
“InvalidOperationException-No process is associated to the object” exception.
Even on using process.HasExited property/process.WaitForInputIdle(),same
exception is thrown.
This exception is thrown during Release as well as Debug mode.
Any idea why this exception occurs ?
Doug Semler - 06 Sep 2007 15:42 GMT
On Sep 6, 9:18 am, Sangeetha <Sangee...@discussions.microsoft.com>
wrote:
> The requirement is to detect closing of a word document opened by a process.
> There is some piece of code which has to be executed after the document is
[quoted text clipped - 12 lines]
>
> Any idea why this exception occurs ?
I don't think you are waiting on the correct Process variable. Make
sure you aren't forgetting to assign the result of Process.Start() to
a variable of type Process.
Process p1 = new Process();
Process p2 = Process.Start("notepad.exe");
p1.WaitForExit(); <-- will throw
p2.WaitForExit(); <-- will not throw.
or....
p1.StartInfo = new ProcessStartInfo("notepad.exe");
p1.Start();
p1.WaitForExit(); <-- will not throw