/// <summary> /// Starts an method running on a new thread. The Thread dies when the method has stopped running. /// You can now make use of the DispatchToMainThread-actions & WaitForNextFrame /// </summary> /// <param name="targetMethod">The method that will be executed by the thread</param> /// <param name="argument">Object to pass to the targetMethod as soon as the Thread is started</param> /// <param name="priority">Thread priority</param> /// <returns>Newly instantiated Thread</returns> public static Thread StartSingleThread(ParameterizedThreadStart targetMethod, object argument, System.Threading.ThreadPriority priority = System.Threading.ThreadPriority.Normal, bool safeMode = true) { Init(); MainThreadWatchdog.Init(); MainThreadDispatcher.Init(); UnityActivityWatchdog.Init(); Thread result = null; if (safeMode) { SafeSingleThreadSession sessionData = new SafeSingleThreadSession(targetMethod); result = new Thread(sessionData.SafeExecte_ParamThreadStart); } else { result = new Thread(targetMethod); } result.Priority = priority; startedThreads.Add(result); result.Start(argument); return(result); }
/// <summary> /// Starts an method running on a new thread. The Thread dies when the method has stopped running. /// You can now make use of the DispatchToMainThread-actions & WaitForNextFrame /// </summary> /// <param name="targetMethod">The method that will be executed by the thread</param> /// <param name="priority">Thread priority</param> /// <returns>Newly instantiated Thread</returns> public static Thread StartSingleThread(ThreadStart targetMethod, System.Threading.ThreadPriority priority = System.Threading.ThreadPriority.Normal, bool safeMode = true) { Init(); MainThreadWatchdog.Init(); MainThreadDispatcher.Init(); Thread result = null; if(safeMode) { SafeSingleThreadSession sessionData = new SafeSingleThreadSession(targetMethod); result = new Thread(sessionData.SafeExecte_ThreadStart); } else { result = new Thread(targetMethod); } result.Priority = priority; startedThreads.Add(result); result.Start(); return result; }