0

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

Community
  • 1
  • 1
Shell
  • 6,818
  • 11
  • 39
  • 70
  • Please add debugging steps you have taken and EXACTLY the issues you have had with each approach you have tried. – FallenAvatar Sep 17 '14 at 04:51
  • Unfortunately this problem is occurred in client's machine not in my PC. So, I could not debug it. I have tested that by creating log entry on every step and I have determine that `c.MainWindowTitle` property does not hold the Document Title in it. It showing blank. I have faced this problem also about a year ago in another PC where VS is installed. The object of Process was not holding values of its any property as I have mentioned in my question *c.MainWindowTitle shows blank, c.HasExited throws exception.* – Shell Sep 17 '14 at 05:08
  • have you asked for OS Version? .Net Version? Have you tried on your computer with debugging? Do they have a "Debug" or "Release" version? – FallenAvatar Sep 17 '14 at 05:10
  • Actually my application is built for .Net 2.0 with 32bit OS (Windows XP) and Client is having both type of machine Windows XP (32bit) and Windows 8 (64bit) and the problem occurred in on 64bit PC. But, I have also tested it on Windows 7(64bit) where VS is installed. In that Windows 7 PC its working. – Shell Sep 17 '14 at 05:19
  • have you looked at the API changes from Windows 7 to Windows 8? Are you aware that EOL for .Net 2.0 happened in 2010? http://support.microsoft.com/lifecycle/search/?sort=pn&alpha=.net+framework – FallenAvatar Sep 17 '14 at 05:33

0 Answers0