المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Windows service Stop issue



C# Programming
06-19-2009, 06:23 AM
Hi,
I have developed 2 applications.
1. Windows Service
2. Asp.net application (Control Panel for above application)
Windows Service has 3 main methods in the following manner.
method1 every 10 mins
method2 every 1hr after method 1
method3 every 3hrs after method 1 n 2.
These methods directly interacts with sql db (for timing the methods etc) and source file ********s etc. These timings and ********s are set via the asp.net control panel. The control panel also puts the service on and off.
My problem is that the control panel puts the service on successfully but while putting it off, it still remains running for quite a while. I think, this happens because my main method(onstart) runs in following fashion.
while(true)
{
if(method1_ellapse_time)
method1
if(method2_ellapse_time)
method2
if(method3_ellapse_time)
method3

load timing settings and source file paths
according to time settings, set method1_ellapse_time,method2_ellapse_time,method3_ellapse_time


Thread.Sleep(5sec)
//if settings are changed i want them to take effect in 5 secs
}
Stopping the service doesn't work as required because while(true) and thread.sleep.Correct me if i am wrong
Is there any better so that i can get rid of sleep and still windows service loads new settings, somehow make the process less cycles consuming and enable stopping as required. Is threading a solution? but why would any one use threading if one process is running? I want single thread exection at a time. Please provide help

Thankyou in advance