Process Info
I am using process.start to start another win app.
When that app is done it displays a message box.
How can (determine when the message box is displayed) I loop until the message box is displayed.
When the message box is displayed I will use Process.kill.
Note: I am using vb.net 2005 & the process I am starting is a console app.
Thank you
Answers
I would change your loop to:
while (fileNotAvailable) Thread.Sleep(100);
So that you're app isn't consuming a hoard of CPU time.
It's not the best solution, the best solution is a command-line switch. Next best might be if the program outputs something consistant right before putting up the message box, you could redirect the console (both stdout and stderr) and watch for that something.- Marked As Answer byCPSS Friday, November 06, 2009 10:17 PM
All Replies
- Hi,
If you close your application in it's own code after the messagebox shown you can use HasExited property of Process.
Here is a sample.
Hope it helps.
Process p=Process.Start("winword"); while (!p.HasExited) { Console.WriteLine("Word Is open"); Thread.Sleep(500); } Console.WriteLine("Word Is closed"); - The app that I am opening reads some information and then creates a text file it then displays a message box indicating that it is done. I need to know when the message box is displayed so that I know the txt file has been written and released. At this point I shutdown the app and read the text out of the file it created. I thought of using Thread.sleep and just giving it a few seconds but was hoping that I would not have to.
Thanks - Although it might be possible to scan for the popup window by it's title bar text, this is a) a lot of work, and b) prone to false positives. Are you sure this console app doesn't have a parameter you can pass to prevent it from opening the message box? Something like "/silent", "-s", "/nopopup", etc.
- No parameter that I am aware of.
I did find a fix i don't know if it is the best but it works.
I created a function that tries to read the file with a streamreader.
If the read throws an error it send back filenotavailable = true. I use "do while filenotavailable = true" to WAIT until the file is available. Once the file is available I kill the process and wait for it to exit then I proced with my code.
Thanks - So what happens to the MessageBox?
No user present to close it?
That other application should now be hung until the MsgBox is closed if it is unattended.
If it is not unattended, why can't the user resume with the original application?
I don't see a major problem here.
Mark the best replies as answers. "Fooling computers since 1971." I would change your loop to:
while (fileNotAvailable) Thread.Sleep(100);
So that you're app isn't consuming a hoard of CPU time.
It's not the best solution, the best solution is a command-line switch. Next best might be if the program outputs something consistant right before putting up the message box, you could redirect the console (both stdout and stderr) and watch for that something.- Marked As Answer byCPSS Friday, November 06, 2009 10:17 PM
- Good Idea
Thanks - I started the process with: Dim myprocess As Process = Process.Start("whatever.exe")
After I know it is done then it kills it and waits for it to exit as follows:
myprocess.Kill()
myprocess.WaitForExit()
So the other app is shutdown. - This is an automated thing; the user starts my program and it deals with the other program and they do not notice.
It is a very quick open and close. I would change your loop to:
while (fileNotAvailable) Thread.Sleep(100);
So that you're app isn't consuming a hoard of CPU time.
It's not the best solution, the best solution is a command-line switch. Next best might be if the program outputs something consistant right before putting up the message box, you could redirect the console (both stdout and stderr) and watch for that something.
Instead of polling to see if the file is created, you may consider using the FileSystemWatcher class which automatically notifies you when file is created.
I agree that redirecting the stdin and stdout of the console app is a good idea.
Another possible solution is to polling the top-level window on the system (http://support.microsoft.com/kb/183009), get the process that is associated with the Window (GetWindowThreadProcessId), and compare the process ID with the ID of your console app. If the match succeeds, it means that you console app has shown the message box, and next you can quit the process.
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


