コード例 #1
0
 /// <summary>
 /// Fire and forget: The MainThread will execute this method witout any arguments to pass, nothing will be returned.
 /// </summary>
 /// <param name="dispatchCall">Example: "() => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name)" </param>
 /// <param name="waitForExecution">Freezes the thread, waiting for the MainThread to execute & finish the "dispatchCall".</param>
 /// <param name="safeMode">Executes all the computations within try-catch events, logging it the message + stacktrace</param>
 public static void DispatchToMainThread(ThreadDispatchDelegate dispatchCall, bool waitForExecution = false, bool safeMode = true)
 {
     ThreadDispatchAction action = new ThreadDispatchAction();
     lock (dispatchActions)
     {
         dispatchActions.Add(action);
     }
     action.Init(dispatchCall, waitForExecution, safeMode);
 }
コード例 #2
0
        //--------------------------------------- UPDATE CALLED BY HELPER --------------------------------------
        //--------------------------------------- UPDATE CALLED BY HELPER --------------------------------------



        //--------------------------------------- 4 DISPATCH OVERLOADS --------------------------------------
        //--------------------------------------- 4 DISPATCH OVERLOADS --------------------------------------
        #region 4 DISPATCH OVERLOADS


        /// <summary>
        /// Fire and forget: The MainThread will execute this method witout any arguments to pass, nothing will be returned.
        /// </summary>
        /// <param name="dispatchCall">Example: "() => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name)" </param>
        /// <param name="waitForExecution">Freezes the thread, waiting for the MainThread to execute & finish the "dispatchCall".</param>
        /// <param name="safeMode">Executes all the computations within try-catch events, logging it the message + stacktrace</param>
        public static void DispatchToMainThread(ThreadDispatchDelegate dispatchCall, bool waitForExecution = false, bool safeMode = true)
        {
            ThreadDispatchAction action = new ThreadDispatchAction();

            lock (dispatchActions)
            {
                dispatchActions.Add(action);
            }
            action.Init(dispatchCall, waitForExecution, safeMode);
        }
コード例 #3
0
 /// <summary>
 /// Fire and forget: The MainThread will execute this method witout any arguments to pass, nothing will be returned.
 /// </summary>
 /// <param name="dispatchCall">Example: "() => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name)" </param>
 /// <param name="waitForExecution">Freezes the thread, waiting for the MainThread to execute & finish the "dispatchCall".</param>
 /// <param name="safeMode">Executes all the computations within try-catch events, logging it the message + stacktrace</param>
 public static void DispatchToMainThread(ThreadDispatchDelegate dispatchCall, bool waitForExecution = false, bool safeMode = true)
 {
     if (MainThreadWatchdog.CheckIfMainThread())
     {
         if (dispatchCall != null)
             dispatchCall();
     }
     else
     {
         ThreadDispatchAction action = new ThreadDispatchAction();
         lock (dispatchActions) { dispatchActions.Add(action); }
         action.Init(dispatchCall, waitForExecution, safeMode);
     }
 }
コード例 #4
0
        //--------------------------------------- UPDATE CALLED BY HELPER --------------------------------------
        //--------------------------------------- UPDATE CALLED BY HELPER --------------------------------------



        //--------------------------------------- 4 DISPATCH OVERLOADS --------------------------------------
        //--------------------------------------- 4 DISPATCH OVERLOADS --------------------------------------
        #region 4 DISPATCH OVERLOADS


        /// <summary>
        /// Fire and forget: The MainThread will execute this method witout any arguments to pass, nothing will be returned.
        /// </summary>
        /// <param name="dispatchCall">Example: "() => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name)" </param>
        /// <param name="waitForExecution">Freezes the thread, waiting for the MainThread to execute & finish the "dispatchCall".</param>
        /// <param name="safeMode">Executes all the computations within try-catch events, logging it the message + stacktrace</param>
        public static void DispatchToMainThread(ThreadDispatchDelegate dispatchCall, bool waitForExecution = false, bool safeMode = true)
        {
            if (MainThreadWatchdog.CheckIfMainThread())
            {
                if (dispatchCall != null)
                {
                    dispatchCall();
                }
            }
            else
            {
                ThreadDispatchAction action = new ThreadDispatchAction();
                lock (dispatchActions) { dispatchActions.Add(action); }
                action.Init(dispatchCall, waitForExecution, safeMode);
            }
        }
コード例 #5
0
        internal static void DispatchToMainThread(ThreadDispatchDelegate dispatchCall, bool safeMode = true)
        {
            if (MainThreadDispatchHelper.CheckIfMainThread())
            {
                if (dispatchCall != null)
                {
                    dispatchCall.Invoke();
                }
            }
            else
            {
                var action = new ThreadDispatchAction();
                lock (DispatchActions)
                {
                    DispatchActions.Add(action);
                }

                action.Init(dispatchCall, safeMode);
            }
        }
コード例 #6
0
 public void Init(ThreadDispatchDelegate dispatchCall, bool safeMode)
 {
     _safeMode          = safeMode;
     _dispatchCallClean = dispatchCall;
 }
        //--------------------------------------- 4 DIFFERENT OVERLOADS --------------------------------------
        //--------------------------------------- 4 DIFFERENT OVERLOADS --------------------------------------
        #region 4 DIFFERENT OVERLOADS

        public void Init(ThreadDispatchDelegate dispatchCall, bool waitForExecution, bool safeMode)
        {
            this.safeMode          = safeMode;
            this.dispatchCallClean = dispatchCall;
            ValidateExecutionOnInit(waitForExecution);
        }
コード例 #8
0
    //--------------------------------------- THREAD WAIT COMMANDS --------------------------------------
    //--------------------------------------- THREAD WAIT COMMANDS --------------------------------------



    //--------------------------------------- 4 DISPATCHER OVERLOADS --------------------------------------
    //--------------------------------------- 4 DISPATCHER OVERLOADS --------------------------------------

    #region 4 DISPATCHER OVERLOADS



    /// <summary>
    /// Fire and forget: The MainThread will execute this method witout any arguments to pass, nothing will be returned.
    /// </summary>
    /// <param name="dispatchCall">Example: "() => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name)" </param>
    /// <param name="waitForExecution">Freezes the thread, waiting for the MainThread to execute & finish the "dispatchCall".</param>
    /// <param name="safeMode">Executes all the computations within try-catch events, logging it the message + stacktrace</param>
    public static void DispatchToMainThread(ThreadDispatchDelegate dispatchCall, bool waitForExecution = false, bool safeMode = true)
    {
        MainThreadDispatcher.DispatchToMainThread(dispatchCall, waitForExecution, safeMode);
    }
コード例 #9
0
 public void Init(ThreadDispatchDelegate dispatchCall, bool waitForExecution, bool safeMode)
 {
     this.safeMode = safeMode;
     this.dispatchCallClean = dispatchCall;
     ValidateExecutionOnInit(waitForExecution);
 }