Beispiel #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);
        }
Beispiel #2
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);
        }