473,396 Members | 2,011 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.

ServiceBase.RequestAdditionalTime(msec) Doesnt work!

Ash
Below is my code...
Was anybody successful in using RequestAdditionalTime? ServiceBase example
on MSDN only requests 4 secs. which is not a good example since the SCM gives
you up to 2 mins anyways but what if you need more.
Am i missing somthing, help appreciated.
Thanks,
-AM
public partial class Service1 : ServiceBase {
StreamWriter myStream;
public Service1() {
InitializeComponent();
myStream = new StreamWriter(new
FileStream(@"c:\log_RequestAdditionalTime.txt", FileMode.OpenOrCreate,
FileAccess.Write));

myStream.WriteLine("----------------------------------------------");
}
Thread workerThread;
protected override void OnStart(string[] args) {
stopInitiated = false;
myStream.BaseStream.Seek(0, SeekOrigin.End);
Log("Service Started");
workerThread = new Thread(new ThreadStart(WorkerThread));
workerThread.Start();

}
bool stopInitiated;
public void WorkerThread() {
Log("Hello, Im the work thread");
while(!stopInitiated) {
Thread.Sleep(300);
}
Log("Stop Initiated, simulating work by counting down");
for(int i = 240; i 0; i--) {
myStream.WriteLine(i);
myStream.Flush();
Thread.Sleep(1000);
}
Log(DateTime.Now + " Done WORK...I am ready to exit
gracefully...");
this.ExitCode = 0;
}

private void initShutDown() {
myStream.BaseStream.Seek(0, SeekOrigin.End);
Log(DateTime.Now + " Returning back to SCM...");
}

private void Log(string msg) {
myStream.WriteLine(DateTime.Now + " " + msg);
myStream.Flush();
}
protected override void OnShutdown() {
Log("System Shutdown signaled ");
initShutDown();
}
protected override void OnStop() {
this.RequestAdditionalTime(250000);
Log("Requesting Additional time...250 secs");
stopInitiated = true;
Log("Service Stop signaled ");
initShutDown();
this.ExitCode = 0;
}
}
Jul 20 '06 #1
0 3387

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

Similar topics

3
by: Jan Waga | last post by:
Hello, Is there some way to control SCM timeout while starting or stopping a C# windows service? I know I can work on a different thread and quickly return from OnStart(), but I'd like my...
0
by: Manfred Braun | last post by:
Hi All, in a windows service application , I add an eventhandler to the Application Domain: public static void Main() { System.ServiceProcess.ServiceBase.Run(new SimpleServiceDemo1());;...
0
by: Mike | last post by:
Hi All, I am using a COM object and so I have to use a form for it to work. The problem is I need to run it as a service as well. When I run it in a test scenario everything works fine and...
6
by: Leonardo Curros | last post by:
Hello, I would like to know what's the best way to restart one service. I would like to do it from the service itself. Is this possible? I try it with ServiceController.stop()...
8
by: vtxr1300 | last post by:
I've followed 2 very similar tutorials on creating a windows service and an installer. But, after successfully compiling it, I try to do the InstallUtil command, but I get a...
6
by: eroc.spam | last post by:
Hello- I'm working with a .NET windows service that can potentially take up to 10 minutes to shutdown. I would like to make it so that SCM doesn't timeout before the service actually stops, but...
6
by: Ash | last post by:
Hi coders, I have a service that does alot of data copying to the database and when the service is stopped or the machine is shutting down it commits the data (in addition to other things) and...
7
by: Brian | last post by:
hello Gentlemen, been trying to get a shell program working where I have a Windows service that also has a Notification icon in the system tray..... I got this idea from microsofts Visual...
23
by: Chizl | last post by:
I created a console app, but most all the code was in classes. I've recently created a windows service, pulled all the classes over and everything compiles fine. Few things I need to understand...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.