473,396 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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?

Oct 19 '07 #1
0 2151

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ray | last post by:
Hi, I just wrote a windows service application to call a function of another object periodically. I used System.Server.Timer and I found that it works fine within the first 2 hours but the...
2
by: Russ McDaniel | last post by:
Originally posted to microsoft.public.dotnet.distributed_apps with no response. Reposted here with additional thoughts. --- Hello, I'm writing a Windows service which performs some...
1
by: JDF | last post by:
I am fairly new to python and seem to have gotten ahead of myself. I am trying to write a Windows service that will return the current number of Citrix sessions to a client. This service will run...
5
by: Richard Steele | last post by:
I have created a WinForm application that needs to be run as a windows service (the PC is inaccesible by any user) i have successfully installed the application as a windows service. When i start...
11
by: Frank Rizzo | last post by:
Hello, My c# based windows service takes a while to dispose. I have to release bunch of resources all over the place and unfortunately it can take 20-40 seconds before I can cleanly exit. ...
0
by: Seth | last post by:
For some reason my service works fine except that it will create the file in my c drive, but will not write to the file. Sorry if this is a duplicate post, i have found some that ask the same...
3
by: zxo102 | last post by:
Hi there, I have a python application (many python scripts) and I start the application like this python myServer.py start in window. It is running in dos window. Now I would like to put it...
6
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class...
9
by: brendan_gallagher_2001 | last post by:
Hi I am seeing some strange behaviour on a windows (vb.net 1.1) service. Basically, what I see happening is that when the Timer1_Elapsed event fires, it attempts to execute Timer1.Stop() but...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.