I am working on windows service, I need to extra time to complete my service one routine slice, service should not terminate during execution of my routine, I tried RequestForAddtionTime(), but it hold the service only upto 2min, I need extra time.
Loading
Soft CornerPosted Jan 19, 2011, 2:13 AM
now it depends on you when ur going to stop the service. i think its quite tough to hold service, try this :
once u start the service , start threading for amount of time which u want :-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
ServiceController Controller = new ServiceController("ServiceName");
Controller.Refresh();
if (Controller.Status == ServiceControllerStatus.Stopped)
{
Controller.Start();
new Thread(Go).Start(); // Call Go() on a new thread
Go();
}
Controller.Refresh();
if (Controller.Status == ServiceControllerStatus.Running)
{
Controller.Stop();
}
///////// Implement below method outside ////////////
static void Go()
{
Thread.Sleep(2000); /// set ur time
}
Naveen SongaraPosted Jan 18, 2011, 9:11 AM
I tried with OnCustomCommand, but I am unable to hold Service Stopping process, when OnStop() event raise..Can you give a example?
Soft CornerPosted Jan 18, 2011, 4:47 AM
I think u should go for OnCustomCommand(int var) in windows service.. If ur code is taking too much of time for execution then customCommand is good for you in service.
Tell me if u still hav a problem..