I know there are lot of post about to hold process until application doesn't get closed.
Actually what I want to do is that when I load the word file in MS Word using Process.Start()
method the application should hold the process until it doesn't get closed. After closing this word file I am also updating it in database. So for that I was using Process.WaitForExit()
method. But, this method doesn't work in some machine. So, I have read about this problem in msdn they have suggested me to use Process.StartInfo.UseShellExecute
property to true
. But, it throws error even the UserName property is assined. So I have decided to create my own method to hold the process.
foreach (Process c in Process.GetProcessesByName("WINWORD"))
{
while (c.MainWindowTitle.Contains("MyDOC NAME") && c.HasExited == false)
{} //this loop will hold the process until Word application doesn't get exited.
}
But, this method also not working. Any property of Process
class object doesn't have any value. c.MainWindowTitle
shows blank, c.HasExited
throws exception.
Now I am stuck here. Neither I can use Process.WaitForExit()
nor above method. I have also another option WMI Query to return current process as solution given in this post. But, i don't think that this method will for in this case. When my OS is not using ShellExecute.
I just want to hold the process until application doesn't get closed.
Any help will be appreciated.
Thanks & Regards