How do you design a method/class that should support cancellation of the operation?
I realized that I never do that in a consistent manner and I want to change that.
Some of the things I have used:
- a boolean property on the class IsCancelled that I synchronize internally. sometimes I have a CanCancel property if the operation cannot be canceled at any given time
- pass a Func< bool > delegate that I repeatedly call to see if the operation has been canceled.
- terminate the thread manually - although this is definitely bad practise
How do you normally do that?