我有一个运行非常长的方法。我希望能够停止,暂停和继续这一method.I看的这个问题,答案是不错,但我想用更一般的图书馆像TPL。 TPL有一个取消机制,但我找不到暂停/继续功能。
I have a method which is running very long. I want to be able to stop, pause and continue the execution of that method.I viewed this question and the answer is nice, but I want to use more general library like TPL. TPL has a cancellation mechanism, but I can't find pause/continue functionality.
修改
感谢所有的答案。但问题是,我不写了长时间运行的方法,我只是调用该方法。
Thanks for all answers. But the problem is that I don't write that "long running" method, I just call that method.
要实现这是一个BackgroundWorker控制的最简单方法。它支持取消和进度报告。
The easiest way to implement this is with a BackgroundWorker control. It supports cancel and progress reporting.
http://msdn.microsoft。 COM / EN-US /库/ cc221403(V = VS.95)的.aspx
http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/48305e65-cea6-4a88-8818-c122e152daa8
修改
哦,我明白了。那么,有暂停和恢复,你没写,除非你想挂起线程的方法不干净的方式。而且,如果该方法不是线程安全的,你可能是出于运气。 http://msdn.microsoft.com/en-us/library/d00bd51t.aspx
Oh, I see. Well, there is no "clean" way of pausing and resuming a method that you didn't write, unless you want to suspend the thread. And, if the method isn't thread-safe, you might be out of luck. http://msdn.microsoft.com/en-us/library/d00bd51t.aspx