![]() |
|
|
|
#1 |
|
Guest
Posts: n/a
|
Service stop timeout
Hi,
I have two windows services running together. One is the main program, and one is an "updater" wrapper for the main. The updater service starts and stops the main one (as in you should never start or stop main service manually, only updater). On most computers it works great, the updater's onStop() can start and stop the main service perfectly. On some computers, though, the updater hangs when it tries to stop the main service. It acutally does stop the service correctly, but it doesnt seem to be getting a return telling it that the other service has stopped, so it sits there until timeout. protected override void OnStop() //for updater { this.eventLog1.WriteEntry("about to try stopping main"); updater.Run.StopService( ); //see below this.eventLog1.WriteEntry("should all be stopped. how long did that take??"); } public static void StopService( ) { SysLog logger = new SysLog(); logger.Log( "Stopping the Updater." ); //some other code goes here StopMain(); //see below logger.Log("main stopped"); return; } private static bool StopMain() { SysLog logger = new SysLog(); logger.Log("stopping Main"); ServiceController sc = null; /* Determine if an instance of Main is running. */ try { sc = new ServiceController("nameOfMainService"); sc.MachineName = "."; Thread.Sleep( 2000 ); } catch( Exception ex ) { throw ex; } try { sc.Refresh(); if ( sc.Status == ServiceControllerStatus.Running || sc.Status == ServiceControllerStatus.StartPending) { logger.Log("in StopMain(): Main is started, need to stop it"); try { logger.Log( "sc.Stop()" ); sc.Stop(); logger.Log( "sc.Stop() done" ); } catch(InvalidOperationException ex) { logger.Error(ex.ToString()); logger.Error(ex.StackTrace); } } } catch(Exception ex) { logger.Error( "Error stopping service. " + ex.ToString() +ex.StackTrace ); throw ex; } return true; } //Main's onStop() protected override void OnStop() { this.eventLog1.WriteEntry("stopping Main. This is where its hanging up"); // Insert code here to define processing. } Ok. So theres the relevant code. The wierd thing is this... if you find in the StopMain() method, there are two logger lines one that outputs "sc.stop()" and one that outputs "sc.stop() done". There is a 30 second delay between these two statements executing. This would cause me to believe taht the hangup is in the onStop method for the Main service. However, if you look at the onStop, the first thing it does is output to the event log. This event log output is 30 seconds after the logger.Log( "sc.Stop()" ); line. There is a 30 second gap here, where i really dont know what is happening. So in summary, there is a 30 second gap between the last thing the StopMain() does before calling sc.stop() and the first thing the onStop() method does, with nothing in between. So, that was a lot. I hope that made sense. Any ideas what would be causing that 30 second timeout there? Advertisement |
| Thread Tools | |
| Display Modes | |
|
|
< Home - Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |