Search code examples
c#multithreadingtimer

c# - How to stop a timer Immediately


I have a System.Timers.Timer with 100 interval. my question is that if I set enable = false in timer, is current working process in timer method stop immediately? or after method finished.

private void watchTags(object obj, ElapsedEventArgs handler)
    {
        for(int i=0 ; i<10000;i++){
            // some works
        }
    }
private void stop_button(){
    watcher.Enabled = false;
}

is my loop immediately stop or after finish?


Solution

  • Okay. as Vijay Kumbhoje said in comments when the timer is finished , any process in watchTags method immediately ends without finishing job.