Alternative to Thread.Sleep in C#?

后端 未结 10 2141
半阙折子戏
半阙折子戏 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:40

    Please see this MSDN reference on the System.Threading.Timer class. There is a great explanation, all of the class members, and some sample code for you to follow when testing/learning.

    Mind you, though, the Timer should be used when you want to fire an event at a certain interval. If you are just looking to pause execution of your application, then you should go with Thread.Sleep(). However, as many others have pointed out, you are causing your thread to sleep for an extended amount of time.

提交回复
热议问题