如何中止长时间运行的方法? [英] How to abort a long running method?
本文介绍了如何中止长时间运行的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个长期运行的方法,我想补充超时进去。难道这样做可行吗?是这样的:
I have a long running method and I want to add timeout into it. Is it feasible to do that? Something like:
AbortWaitSeconds(20)
{
this.LongRunningMethod();
}
在哪里,当它达到了20秒,该方法将被中止。该方法没有循环,我没有控制/ code在那个方法。
Where when it reached 20 seconds, the method will be aborted. The method doesn't have loop and I do not have a control/code over that method.
推荐答案
请参阅我回答这个问题一个通用解决方案。
See my answer to this question for a generic solution.
这篇关于如何中止长时间运行的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文