Alternatives to Thread.Sleep()

后端 未结 11 1277
清歌不尽
清歌不尽 2020-11-27 03:48

Every N minutes we want to run through a list of tasks. So we\'ve created a task executor with a

do { DoWork(); }while(!stopRequested)

No

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 04:39

    Thread.Sleep isn't the devil - you could use it for a scenario like this. It's just not very reliable for short durations.

    Using a WaitHandle is a good option - but you need a specific instance of a wait handle. It won't do this alone, however.

    That being said, most of the time, operations like this are better suited towards using a Timer. Is there a reason you're trying to process this in a loop rather than just using a Timer to start off the work item?

提交回复
热议问题