timer in windows service- continue running after the service is stopped. RRS feed

  • Question

  • Hi, I have a windows service in which I have used a Timer to run the process on some time interval. 

    and In the timer I have used Used Thread for the process. Now On stop event I have aborted the thread but did not closed or dispose the timer. Now I have got a problem that I have stopped the  service. But I am getting Emails from the service on the specified time. Unable to understand that when the service is stopped then from where the code is running. 

    Now I want to understand that whether the timer is running in back ground, IF yes then from where Can I see that and if not the How is running my code.


    Tuesday, February 4, 2014 11:35 AM

All replies

  • What people normally do is to create a log file in a service and save debug info to the log file.


    Tuesday, February 4, 2014 11:55 AM
  • any other way to know the timer is running on the server.


    Tuesday, February 4, 2014 2:04 PM
  • Hi,

    Basically my timer has Change time of 24 hours, some where I found that the Change is queued some where in Thread Pool in windows, Is this possible to find the list of queued timer.

    and other Think I want know how to dispose the Timer and the queued timer callback .

    as this code says that after completion of the callback we can dispose the time but I want to dispose any time ..

    You can Dispose all timers with WaitHandler parameter. This handler will be signaled only when callback method is completed (as spec says: "The timer is not disposed until all currently queued callbacks have completed.")

    void WaitUntilCompleted(List<Timer> myTimers)
        List<WaitHandle> waitHnd = new List<WaitHandle>();
        foreach (var timer in myTimers)
            WaitHandle h = new AutoResetEvent(false);


    • Edited by santosh jha Thursday, February 6, 2014 5:37 AM add some code
    Thursday, February 6, 2014 4:32 AM
  • All events are registerd with the timer tick services.  I use to know in DOS how to get the list, but never did it with windows operating system.  I'm not sure you can because of protections that were added to windows operating system that dos didn't have.  You may be able to get only the timers owned by your login and not the windows owned events.  As I said I really don't get into the windows operating system low level drivers.


    Thursday, February 6, 2014 7:53 AM
  • Hi,

    How to kill timer which is scheduled - callback is after 24 hours. 

    as after disposing the timer the callback is running on the specified time. 

    Is this possible to kill the callback scheduled manually.


    Friday, February 14, 2014 1:25 PM