public static void Invoke(Action method, int milliseconds) { Thread thdToKill = null; Action invokemethod = new Action(() => { thdToKill = Thread.CurrentThread; method(); }); IAsyncResult ar = invokemethod.BeginInvoke(null, null); if (!ar.AsyncWaitHandle.WaitOne(milliseconds)) { thdToKill.Abort(); throw new Exception(string.Format("操作失败,原因:超时 {0}毫秒", milliseconds)); } invokemethod.EndInvoke(ar); }
时间: 2024-10-03 23:00:26