コード例 #1
0
 public static bool TryAbort(this Thread thread, int timeoutMss, int pollTimeSpanMss = 300)
 {
     if (thread == null || !thread.IsAlive)
     {
         return(true);
     }
     return(SleepRoutines.WaitForCondition(() => { thread.Abort(); thread.Join(pollTimeSpanMss); return !thread.IsAlive; }, timeoutMss));
 }
コード例 #2
0
 public static bool TryKill(this Process process, int timeoutMss = 1000, int pollTimeSpanMss = 300)
 {
     return(SleepRoutines.WaitForCondition(() =>
     {
         try
         {
             process.Kill();
         }
         catch
         {
             // Process already exited.
             return true;
         }
         process.WaitForExit(pollTimeSpanMss);
         return !process.IsRunning();
     },
                                           timeoutMss
                                           ));
 }