Finalizers and Dispose

后端 未结 6 1551
失恋的感觉
失恋的感觉 2021-01-01 06:04

I\'ve got a class named BackgroundWorker that has a thread constantly running. To turn this thread off, an instance variable named stop to needs to

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 06:52

    You need the full disposable pattern but the stop has to be something the thread can access. If it is a member variable of the class being disposed, that's no good because it can't reference a disposed class. Consider having an event that the thread owns and signaling that on dispose instead.

提交回复
热议问题