/// <summary> /// Start a new thread that is tracked by the watchdog /// </summary> /// <param name="start">The method that will be executed in a new thread</param> /// <param name="name">A name to give to the new thread</param> /// <param name="priority">Priority to run the thread at</param> /// <param name="isBackground">True to run this thread as a background /// thread, otherwise false</param> /// <param name="alarmIfTimeout">Trigger an alarm function is we have timed out</param> /// <param name="alarmMethod"> /// Alarm method to call if alarmIfTimeout is true and there is a timeout. /// Normally, this will just return some useful debugging information. /// </param> /// <param name="timeout">Number of milliseconds to wait until we issue a warning about timeout.</param> /// <param name="log">If true then creation of thread is logged.</param> /// <returns>The newly created Thread object</returns> public static Thread StartThread( ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout, Func <string> alarmMethod, int timeout, bool log = true, bool SuspendFlow = true) { Thread thread; if (SuspendFlow) { using (ExecutionContext.SuppressFlow()) { thread = new Thread(start); } } else { thread = new Thread(start); } thread.Priority = priority; thread.IsBackground = isBackground; thread.Name = name; Watchdog.ThreadWatchdogInfo twi = new Watchdog.ThreadWatchdogInfo(thread, timeout, name) { AlarmIfTimeout = alarmIfTimeout, AlarmMethod = alarmMethod }; Watchdog.AddThread(twi, name, log); thread.Start(); return(thread); }
public static Thread StartThread( ThreadStart start, string name, ThreadPriority priority, int stackSize = -1, bool suspendflow = true) { Thread thread; if (suspendflow) { using (ExecutionContext.SuppressFlow()) { if (stackSize > 0) { thread = new Thread(start, stackSize); } else { thread = new Thread(start); } } } else { if (stackSize > 0) { thread = new Thread(start, stackSize); } else { thread = new Thread(start); } } thread.Priority = priority; thread.IsBackground = true; thread.Name = name; Watchdog.ThreadWatchdogInfo twi = new Watchdog.ThreadWatchdogInfo(thread, Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS, name) { AlarmIfTimeout = false, AlarmMethod = null }; Watchdog.AddThread(twi, name, false); thread.Start(); return(thread); }
/// <summary> /// Start a new thread that is tracked by the watchdog /// </summary> /// <param name="start">The method that will be executed in a new thread</param> /// <param name="name">A name to give to the new thread</param> /// <param name="priority">Priority to run the thread at</param> /// <param name="isBackground">True to run this thread as a background /// thread, otherwise false</param> /// <param name="alarmIfTimeout">Trigger an alarm function is we have timed out</param> /// <param name="alarmMethod"> /// Alarm method to call if alarmIfTimeout is true and there is a timeout. /// Normally, this will just return some useful debugging information. /// </param> /// <param name="timeout">Number of milliseconds to wait until we issue a warning about timeout.</param> /// <param name="log">If true then creation of thread is logged.</param> /// <returns>The newly created Thread object</returns> public static Thread StartThread( ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout, Func <string> alarmMethod, int timeout, bool log = true) { Thread thread = new Thread(start); thread.Priority = priority; thread.IsBackground = isBackground; thread.Name = name; Watchdog.ThreadWatchdogInfo twi = new Watchdog.ThreadWatchdogInfo(thread, timeout, name) { AlarmIfTimeout = alarmIfTimeout, AlarmMethod = alarmMethod }; Watchdog.AddThread(twi, name, log: log); thread.Start(); return(thread); }
/// <summary> /// Start a new thread that is tracked by the watchdog /// </summary> /// <param name="start">The method that will be executed in a new thread</param> /// <param name="name">A name to give to the new thread</param> /// <param name="priority">Priority to run the thread at</param> /// <param name="isBackground">True to run this thread as a background /// thread, otherwise false</param> /// <param name="alarmIfTimeout">Trigger an alarm function is we have timed out</param> /// <param name="alarmMethod"> /// Alarm method to call if alarmIfTimeout is true and there is a timeout. /// Normally, this will just return some useful debugging information. /// </param> /// <param name="timeout">Number of milliseconds to wait until we issue a warning about timeout.</param> /// <param name="log">If true then creation of thread is logged.</param> /// <returns>The newly created Thread object</returns> public static Thread StartThread( ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout, Func<string> alarmMethod, int timeout, bool log = true) { Thread thread = new Thread(start); thread.Priority = priority; thread.IsBackground = isBackground; Watchdog.ThreadWatchdogInfo twi = new Watchdog.ThreadWatchdogInfo(thread, timeout, name) { AlarmIfTimeout = alarmIfTimeout, AlarmMethod = alarmMethod }; Watchdog.AddThread(twi, name, log:log); thread.Start(); thread.Name = name; return thread; }