Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
 public static void SleepOrAbortIfUnityInactive()
 {
     UnityActivityWatchdog.Init();
     while (!UnityActivityWatchdog.combinedActive && !MainThreadWatchdog.CheckIfMainThread())
     {
         bool flag = UnityActivityWatchdog.unityRunning;
         if (flag)
         {
             Thread.Sleep(100);
         }
         else
         {
             Thread.CurrentThread.Interrupt();
             Thread.CurrentThread.Join();
         }
     }
 }
Esempio n. 3
0
        public static Thread StartSingleThread(ParameterizedThreadStart targetMethod, object argument, System.Threading.ThreadPriority priority = System.Threading.ThreadPriority.Normal, bool safeMode = true)
        {
            SingleThreadStarter.Init();
            MainThreadWatchdog.Init();
            MainThreadDispatcher.Init();
            UnityActivityWatchdog.Init();
            Thread thread;

            if (safeMode)
            {
                SingleThreadStarter.SafeSingleThreadSession @object = new SingleThreadStarter.SafeSingleThreadSession(targetMethod);
                thread = new Thread(new ParameterizedThreadStart(@object.SafeExecte_ParamThreadStart));
            }
            else
            {
                thread = new Thread(targetMethod);
            }
            thread.Priority = priority;
            SingleThreadStarter.startedThreads.Add(thread);
            thread.Start(argument);
            return(thread);
        }
 private void Awake()
 {
     MainThreadWatchdog.Init();
     UnityActivityWatchdog.Init();
     InvokeRepeating("UpdateMainThreadDispatcher", WaitForSecondsTime, WaitForSecondsTime);
 }
Esempio n. 5
0
 public static bool CheckUnityActive()
 {
     UnityActivityWatchdog.Init();
     return(UnityActivityWatchdog.combinedActive);
 }