Wait for a while without blocking main thread

前端 未结 8 1003
慢半拍i
慢半拍i 2020-12-01 20:50

I wish my method to wait about 500 ms and then check if some flag has changed. How to complete this without blocking the rest of my application?

8条回答
  •  遥遥无期
    2020-12-01 21:24

    I don't really understand the question.

    If you want to block before checking, use Thread.Sleep(500);

    If you want to check asynchronously every x seconds, you can use a Timer to execute a handler every x milliseconds.

    This will not block your current thread.

提交回复
热议问题