开发者

Can a c# timer call the .stop function on itself?

开发者 https://www.devze.com 2023-02-20 04:55 出处:网络
Whenever I try to do something like this the timer doesnt stop: private void timer1_Tick(object sender, EventArgs e)

Whenever I try to do something like this the timer doesnt stop:

private void timer1_Tick(object sender, EventArgs e)
    {

        if ((开发者_如何学CaddedToFriendsCounter == 4) || (followJobFinished))
        {
    //stop the timer
    }
}

Any suggestions?


Yes, no problem. A comment can't stop a timer. Use

 timer1.Stop();

or

 ((Timer)sender).Stop();


There's no problem stopping the timer from within the Tick event handler. What the heck is addedToFriendsCount and followJobFinished? Your error is either with one of these or the code for //stop the timer.


Yes, there is no problem stopping the timer from the Tick event. The event runs in the main thread, so there is no cross-thread problems when you access the Timer control.

You can stop the timer either by calling the Stop method or by setting the Enabled property to false.

0

精彩评论

暂无评论...
验证码 换一张
取 消