Alternative to Thread.Sleep in C#?

后端 未结 10 2139
半阙折子戏
半阙折子戏 2020-12-19 07:10

I have a code which when run, it executes series of lines in sequence. I would like to add a pause in between.

Currently, I have it like this

//do wo         


        
10条回答
  •  醉酒成梦
    2020-12-19 07:43

    USE A TIMER!

    private DispatcherTimer Timer;
    public Constructor
    {
        Timer = new System.Windows.Threading.DispatcherTimer();
        Timer.Tick += new EventHandler(Timer_Tick);
        Timer.Interval = new TimeSpan(0,0,10);
        Timer.Start();
    }
    
    
    private void Timer_Tick(object sender, EventArgs e)
    {
        Timer.Stop();
        Timer -= Timer_Tick;
        Timer = null;
        // DO SOMETHING
    }
    

提交回复
热议问题