C# - Alternative to Thread.Sleep?

前端 未结 4 1929
失恋的感觉
失恋的感觉 2021-01-26 17:13

I\'m doing all this in C#, in Visual Studio 2008.

I want to slow down the work of my algorithm so that the user can watch it\'s work. There is a periodic change visible

4条回答
  •  醉话见心
    2021-01-26 18:05

    First off, don't make the user wait for work that is done before they even think about when it will be finished. Its pointless. Please, just say no.

    Second, you're "sleeping" the UI thread. That's why the UI thread is "locking up." The UI thread cannot be blocked; if it is, the UI thread cannot update controls on your forms and respond to system messages. Responding to system messages is an important task of the UI thread; failing to do so makes your application appear locked up to the System. Not a good thing.

    If you want to accomplish this (please don't) just create a Timer when you start doing work that, when it Ticks, indicates its time to stop pretending to do work.

    Again, please don't do this.

提交回复
热议问题