C# timer stop after some number of ticks automatically

前端 未结 5 1849
梦谈多话
梦谈多话 2021-01-18 05:53

How to stop a timer after some numbers of ticks or after, let\'s say, 3-4 seconds?

So I start a timer and I want after 10 ticks or after 2-3 seconds to stop autom

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 06:02

    You can keep a counter like

     int counter = 0;
    

    then in every tick you increment it. After your limit you can stop timer then. Do this in your tick event

     counter++;
     if(counter ==10)  //or whatever your limit is
       yourtimer.Stop();
    

提交回复
热议问题