Making asynchronous code cancellable
问题 I have some time-consuming method: public class TimeConsumingClass { public void TimeConsumingMethod() { //let's imagine my method works this way for (var i = 0; i < 10000; i++) Thread.Sleep(); } } It was executed in main thread previously. Then I needed to call it in secondary thread to not block UI: Task.Factory.StartNew(() => { new TimeConsumingClass().TimeConsumingMethod(); }); And now I need to make it possible to stop this method at any time. So I want to make my method treat