//UtilProcess.KillProcessByName(System.IO.Path.GetFileName(_appPath)); public static void KillAllProcessesByName(params string[] ps) { foreach (var p in ps) { KillProcessByName(p); UtilTime.WaitTime(0.2); } }
public static Thread WaitTimeElapseThread(string comment, int times = -1) { return(new Thread(() => { var s = 0; while (true) { UtilTime.WaitTime(1); UtilCmd.WriteTitle($"{comment} Please Wait... Time elapsed {s++}s "); if (s == times) { return; } } })); }
private static T ForWhat <T>(Func <T> action, double maxWaitTimeInSec = -1, int intervalInSec = -1, dynamic expectedResult = null) { var exceptionMsg = ""; if (maxWaitTimeInSec == -1) { maxWaitTimeInSec = CompMaxWaitTimeInSec < 0 ? MaxWaitTimeInSec : CompMaxWaitTimeInSec; } if (intervalInSec == -1) { intervalInSec = CompIntervalInSec < 0 ? IntervalInSec : CompIntervalInSec; } var dt = DateTime.Now; do { if (UtilTime.DateDiff(dt, DateTime.Now, UtilTime.DateInterval.Second) > Convert.ToDouble(maxWaitTimeInSec)) { throw new Exception($"UtilWait > Timeout! The max timeout is {maxWaitTimeInSec}s. The last exception message is {exceptionMsg}."); } try { var actualResult = action.Invoke(); switch (expectedResult) { case ResultType.ForTrue when actualResult.ToString() == "True": return(actualResult); case ResultType.AnyResult: return(actualResult); case ResultType.NonNullResult when actualResult != null: return(actualResult); } } catch (Exception ex) { exceptionMsg = ex.Message; } UtilTime.WaitTime(intervalInSec); } while(true); }