Can I use a timer to update a label every x milliseconds

前端 未结 4 1039
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-20 10:32

This is my code:

Stopwatch timer = new Stopwatch();
timer.Start();
while (timer.ElapsedMilliseconds < 3000) {
    label1.Text = Convert.ToString( timer.El         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-20 11:17

    You better to use System.Windows.Forms.Timer for this, and not Stopwatch()

    Even if that timer is less accurate then StopWatch(..) it gives you a good control.

    Just example sniplet:

       myTimer.Tick += new EventHandler(TimerEventProcessor);       
       myTimer.Interval = 1350;
       myTimer.Start();
    
       private void TimerEventProcessor(...){          
         label1.Text = "...";
       }
    

提交回复
热议问题