Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, February 20, 2009 8:04 PM
I want to open "Notes" application in my app and wait for it to close, so that I can use some data created by Notes application (like new notes etc..)
I use the following code:
string target = "notes";
Process process = new Process();
process.StartInfo.FileName = target;
process.Start();
process.WaitForExit();// wait for the 'notes' application to close
//check for new notes.. and write some code..
But the problem is that process.WaitForExit() just waits till Notes is launched successfully.
I thought from the documentation that WaitForExit will wait for Exit of Notes application.
Is this a mistake in my understanding of the API?
How do we do this in c# (PocketPC).
I am targetting Windows Mobile SDK 6 (C#) for my code.
Any help / advice is appreciated.
All replies (8)
Friday, February 20, 2009 8:08 PM
My guess is that Notes.exe exits after spawning a second executable. So the WaitForExit returns when that happens. http://blog.voidnish.com
Friday, February 20, 2009 8:13 PM
Let's read what MSDN says about it:
The
WaitForExit()()() overload is used to make the current thread wait until the associated process terminates. This method instructs the Process component to wait an infinite amount of time for the process to exit. This can cause an application to stop responding. For example, if you call CloseMainWindow for a process that has a user interface, the request to the operating system to terminate the associated process might not be handled if the process is written to never enter its message loop.
*This overload ensures that all processing has been completed, including the handling of asynchronous events for redirected standard output. You should use this overload after a call to the WaitForExit(Int32) overload when standard output has been redirected to asynchronous event handlers.
*
This is of course for .NET. What makes you think that it does not wait for the Note process to finish? What are the signs of that? What is the proof?
AlexB
Friday, February 20, 2009 11:03 PM
Not sure if this has changed recently but 'back in the day' applications on window mobile never really closed when you hit the X to close them, they would just minimize and keep running in the background (this was not a bug,it was a feature, since next time you start the app it would be started *really* fast, yah i know, insane but true) so that could be why WaitForExit is perhaps behaving strangely and waiting for app startup instead of exit. but then again it is just speculation based on knowlegde of ancient versions of windows mobile.
Monday, June 8, 2009 10:45 PM
I'd like to bump this question up.
I'm on Windows Mobile 6 Standard and I'm trying to spawn a browser instance. I'd like to wait until the user closes the browser. But WaitForExit returns extremely fast.
Here is the code:
Process p = new Process();
p.StartInfo.Arguments = "http://www.example-site.com";
p.StartInfo.Verb = "Open";
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "IExplore.exe";
p.Start();
p.WaitForExit();
MessageBox.Show("Now the browser should be closed");
What should be the right way to get the expected resuts?
Alessandro
Tuesday, June 9, 2009 9:58 PM
Try this:
Process.Start ( "iexplore", "http://finance.yahoo.com/q/hp?s=" + symbol );
Where symbol is..... symbol.AlexB
Wednesday, September 2, 2009 8:35 PM
I'm seeing the same problem, but on XP. I think the proof can be seen in any debugger (as I am seeing), or in any console application (not necessarily on Mobile)
Wednesday, September 2, 2009 8:48 PM
Except that you don't then get a process object that you can use. If you try
Dim myProc As New Process()
myProc = Process.Start ( "iexplore", "http://finance.yahoo.com/q/hp?s=" + symbol );
myProc.WaitForExit()
It *still* returns immediately.
Wednesday, September 2, 2009 8:52 PM
Problem is you are not starting a new instance of iexplore.exe. You are just creating a new window on the existing process.
My guess is iexplore.exe starts, sees a previous instance and communicates with the previous instance so that it opens the new window, and then this instance you started exits immediately.
So the behavior is correct and to be expected.http://blog.voidnish.com