开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜