Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have already designed an exe and Now I want to launch this EXE using windows service. main purpose it to check after every 30 minutes either that EXE is running or not using that windows service. If not running then windows service will start it.

Regard's
Shahid Mehmood
Posted

Have a look on similar QA[^], check if you get some help out.
 
Share this answer
 
You can use a BackgroundWorker for the threading, use Process.WaitForExit() to wait for the process to terminate until you stop your service.

You're right that you should do some threading, doing lots of work in the OnStart may render errors about not starting correctly from Windows when starting the service.
protected override void OnStart(string[] args) 
{ 
 
    BackgroundWorker bw = new BackgroundWorker(); 
    bw.DoWork += new DoWorkEventHandler(bw_DoWork); 
    bw.RunWorkerAsync(); 
} 
 
private void bw_DoWork(object sender, DoWorkEventArgs e) 
{ 
    Process p = new Process(); 
    p.StartInfo = new ProcessStartInfo("file.exe"); 
    p.Start(); 
    p.WaitForExit(); 
    base.Stop(); 
} 


Edit You may also want to move the Process p to a class member and stop the process in the OnStop to make sure that you can stop the service again if the exe goes haywire.
protected override void OnStop() 
{ 
    p.Kill(); 
}
 
Share this answer
 
v4
BackgroundWorker() is not declared. what is that. where is RunWorkerAsync() defined is detail avail.

any suggestion in just few lines required no Code is necessary just to know how it could be possible. if example then appreciated.
 
Share this answer
 
Comments
Aarti Meswania 5-Sep-12 3:42am    
use "Have a Question or Comment?" button for reply. because if u will use add solution the person will not get mail that you have some query on his/her answer,
:)
VB
System.Diagnostics.Process.Start("C:\YourExe.exe")

Happy Coding!
:)
 
Share this answer
 

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