AutoResetEvent vs. boolean to stop a thread

后端 未结 5 661
栀梦
栀梦 2020-12-14 21:59

I have an object in a worker thread, which I can instruct to stop running. I can implement this using a bool or an AutoResetEvent:

boolean:

private v         


        
5条回答
  •  独厮守ぢ
    2020-12-14 22:41

    It depends if the above snippet is all you are doing or not. The AutoReset event, as its name suggests, gets reset after the WaitOne is passed. This means that you could then use it again straightaway, rather than with the bool, having to set it back to true.

提交回复
热议问题