Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi,i wrote an window form application in vb.net.in that application form load event i try to start three another form application(exe).so when i run my application my form load event is complete before that three exe start.so my question is how i hold or pause my form load event for some time so that three exe will be start??

my code is here...
C#
form1_load()
{
   system.diagnostic.process.start("first.exe")
   system.diagnostic.process.start("second.exe")  
   system.diagnostic.process.start("third.exe")    
}

i also tried thread.sleep() among start process call but it is failed.
Posted
Updated 9-Jul-12 8:50am
v2

Move the Process.Start instructions from the Form.Load event to the Form constructor - you could also hold your constructor from completing until the other apps are running, by check calling Process.GetProcessByName and ensuring they are all there.
 
Share this answer
 
Comments
RICKY_Xxx 10-Jul-12 3:29am    
i tried it constructor also but it is failed my form load is start before exe.
OriginalGriff 10-Jul-12 3:33am    
Did you check if they were up and running before completing the constructor?
RICKY_Xxx 10-Jul-12 4:46am    
yes i called it up before completing constuctor.but that exe take time to run completly
Depending on the processes you are starting you might be able to do something like this

System.Diagnostics.Process proc = System.Diagnostics.Process.Start("name.exe");
proc.WaitForInputIdle();


There is also an overload for WaitForInputIdle(int timeout) so it will only wait so long and then return.
 
Share this answer
 
Comments
RICKY_Xxx 10-Jul-12 0:20am    
still form load event is complete before exe start.
Trak4Net 10-Jul-12 2:10am    
Ok, the WaitForInputIdle only works if the exe has a GUI or message pump. Probably the best bet is to have a controlled loop and perform the method from solution 1 above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900