ServiceBase.RequestAdditionalTime(msec) Doesnt work!

G

Guest

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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top