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);
        }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-12
  • 2022-12-23
  • 2021-11-01
  • 2022-02-17
  • 2021-11-18
  • 2022-12-23
相关资源
相似解决方案