AutoResetEvent vs. boolean to stop a thread

后端 未结 5 660
栀梦
栀梦 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

    IMHO the AutoResetEvent is better, because you can't forget the crucial volatile keyword in this case.

提交回复
热议问题