Quick Notes for easy understanding. Chapters are on C#.Net,Linq,OOPS,Design Patterns,UML,Tools for development, Databases and many others. - Sid
Wednesday, November 27, 2013
Self Restarting Windows Service.
I had an situation in my Windows Service. There was a connectivity issue when dealing with the Email server. Email Server connectivity was using 3rd party .dll. and it was making productivity down. So to bring it up only solution was to restart the Service manually. To fix it automatically we need to fix in the same service writing code to restart itself. But it is not so easy. Self stop and start is not possible with out the help of another process.
Solution 1:
Creating other process telling it to stop and start the service.
Process proc = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.CreateNoWindow = true;
psi.FileName = "cmd.exe";
psi.Arguments = "/C net stop SERVERNAME && net start SERVERNAME ";
psi.LoadUserProfile = false;
psi.UseShellExecute = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo = psi;
proc.Start();
Solution 2:
Call, Environment.Exit with an error code greater than 0, which seems appropriate. Then on install we configure the service to restart on error.
Environment.Exit(1);
Subscribe to:
Post Comments (Atom)
Code Formater
Paste Here Your Source Code | ||||||||||||||
Source Code Formatting Options | ||||||||||||||
|
||||||||||||||
Copy Formatted Source Code | ||||||||||||||
Preview Of Formatted Code |
No comments:
Post a Comment