添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
强健的黑框眼镜  ·  asp.net ...·  1 年前    · 
宽容的大熊猫  ·  Mounting a Single ...·  1 年前    · 
大力的烤面包  ·  好用的 Android ...·  2 年前    · 
拉风的蟠桃  ·  Spring Java ...·  2 年前    · 
// try the five second method with a 6 second timeout CallWithTimeout(FiveSecondMethod, 6000 ); // try the five second method with a 4 second timeout // this will throw a timeout exception CallWithTimeout(FiveSecondMethod, 4000 ); static void FiveSecondMethod() Thread.Sleep( 5000 ); static void CallWithTimeout(Action action, int timeoutMilliseconds) Thread threadToKill = null ; Action wrappedAction = () => threadToKill = Thread.CurrentThread; action(); IAsyncResult result = wrappedAction.BeginInvoke( null , null ); if (result.AsyncWaitHandle.WaitOne(timeoutMilliseconds)) wrappedAction.EndInvoke(result); threadToKill.Abort(); throw new TimeoutException();