WaitForExit for programs of type MS Word - process already started
In my app I want to open *.rtf file, and than wait for it to be closed. Often user has MS Word to open *.rtf files and here is the problem. Code below works, but only when "WINWORD" process has not been started yet. When it is, calling Process.Start() opens only a new window of Word, and most of data from Process object becomes empty. I can't 'wait' for process, cuz it throws an exception. How can I deal with it? Please, help.
Process p = new Process();
p.StartInfo.FileName = @"C:\Users\UserName\Desktop\MyFile.rtf";
p.Start();
string name = p.ProcessName;
p.WaitForExit();
Console.WriteLine(name + " has exited");
Console.ReadKey();
*Edit: I have analyzed some solutions, and I have noticed, that if application by which user opens the *.rtf file is like Word (may open many files in many windows), I have to wait only for my *.rtf file window, not whole Process. It开发者_Go百科 would be stupid. The problem is more and more complicated. Please Help.
精彩评论