public static T DispatchToMainThreadReturn <T>(CallBackReturn <T> dispatchCall, bool safeMode = true)
        {
            bool flag = MainThreadWatchdog.CheckIfMainThread();
            T    result;

            if (flag)
            {
                bool flag2 = dispatchCall != null;
                if (flag2)
                {
                    result = dispatchCall();
                }
                else
                {
                    result = default(T);
                }
            }
            else
            {
                ThreadDispatchAction <T> threadDispatchAction = new ThreadDispatchAction <T>();
                MainThreadDispatcher.dispatchActions.Enqueue(threadDispatchAction);
                threadDispatchAction.Init(dispatchCall, safeMode);
                result = threadDispatchAction.dispatchExecutionResult2;
            }
            return(result);
        }
        public static object DispatchToMainThreadReturn <T>(CallBackArgRturn <T> dispatchCall, T dispatchArgument, bool safeMode = true)
        {
            bool   flag = MainThreadWatchdog.CheckIfMainThread();
            object result;

            if (flag)
            {
                bool flag2 = dispatchCall != null;
                if (flag2)
                {
                    result = dispatchCall(dispatchArgument);
                }
                else
                {
                    result = null;
                }
            }
            else
            {
                ThreadDispatchAction <T> threadDispatchAction = new ThreadDispatchAction <T>();
                MainThreadDispatcher.dispatchActions.Enqueue(threadDispatchAction);
                threadDispatchAction.Init(dispatchCall, dispatchArgument, safeMode);
                result = threadDispatchAction.dispatchExecutionResult;
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// When executed by the MainThread, this argument will be passed to the "dispatchCall";
        /// </summary>
        /// <param name="dispatchCall">Example: "(object obj) => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name + "\nObject: " + obj.toString())"</param>
        /// <param name="dispatchArgument">Once the MainThread executes this action, the argument will be passed to the delegate</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(ThreadDispatchDelegateArg dispatchCall, object dispatchArgument, bool waitForExecution = false, bool safeMode = true)
        {
            ThreadDispatchAction action = new ThreadDispatchAction();

            lock (dispatchActions)
            {
                dispatchActions.Add(action);
            }
            action.Init(dispatchCall, dispatchArgument, waitForExecution, safeMode);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Allows you to dispatch an delegate returning an object (for example: a newly instantiated gameobject) that is directly available in your ThreadPool-Thread.
        /// Because the thread you are dispatching from is not the MainThread, your ThreadPool-thread needs to wait till the MainThread executed the method, and the returned value can be used directly
        /// </summary>
        /// <param name="dispatchCall">Example: "(object obj) => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name + "\nObject: " + obj.toString())"</param>
        /// <param name="safeMode">Executes all the computations within try-catch events, logging it the message + stacktrace</param>
        /// <returns>After the MainThread has executed the "dispatchCall" (and the worker-thread has been waiting), it will return whatever the dispatchCall returns to the worker-thread</returns>
        public static object DispatchToMainThreadReturn(ThreadDispatchDelegateReturn dispatchCall, bool safeMode = true)
        {
            ThreadDispatchAction action = new ThreadDispatchAction();

            lock (dispatchActions)
            {
                dispatchActions.Add(action);
            }
            action.Init(dispatchCall, safeMode); //Puts the Thread to sleep while waiting for the action to be invoked.
            return(action.dispatchExecutionResult);
        }
Exemplo n.º 5
0
 /// <summary>
 /// When executed by the MainThread, this argument will be passed to the "dispatchCall";
 /// </summary>
 /// <param name="dispatchCall">Example: "(object obj) => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name + "\nObject: " + obj.toString())"</param>
 /// <param name="dispatchArgument">Once the MainThread executes this action, the argument will be passed to the delegate</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(ThreadDispatchDelegateArg dispatchCall, object dispatchArgument, bool waitForExecution = false, bool safeMode = true)
 {
     if (MainThreadWatchdog.CheckIfMainThread())
     {
         if (dispatchCall != null)
         {
             dispatchCall(dispatchArgument);
         }
     }
     else
     {
         ThreadDispatchAction action = new ThreadDispatchAction();
         lock (dispatchActions) { dispatchActions.Add(action); }
         action.Init(dispatchCall, dispatchArgument, waitForExecution, safeMode);
     }
 }
Exemplo n.º 6
0
 public static void DispatchToMainThread <T>(CallBackArg <T> dispatchCall, T dispatchArgument, bool waitForExecution = false, bool safeMode = true)
 {
     if (MainThreadWatchdog.CheckIfMainThread())
     {
         if (dispatchCall != null)
         {
             dispatchCall(dispatchArgument);
         }
     }
     else
     {
         ThreadDispatchAction <T> t = new ThreadDispatchAction <T>();
         dispatchActions.Enqueue(t);
         t.Init(dispatchCall, dispatchArgument, waitForExecution, safeMode);
     }
 }
Exemplo n.º 7
0
 public static void DispatchToMainThread(CallBack dispatchCall, bool waitForExecution = false, bool safeMode = true)
 {
     if (MainThreadWatchdog.CheckIfMainThread())
     {
         if (dispatchCall != null)
         {
             dispatchCall();
         }
     }
     else
     {
         ThreadDispatchAction <object> t = new ThreadDispatchAction <object>();
         dispatchActions.Enqueue(t);
         t.Init(dispatchCall, waitForExecution, safeMode);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Allows you to dispatch an delegate returning an object (for example: a newly instantiated gameobject) that is directly available in your ThreadPool-Thread.
 /// Because the thread you are dispatching from is not the MainThread, your ThreadPool-thread needs to wait till the MainThread executed the method, and the returned value can be used directly
 /// </summary>
 /// <param name="dispatchCall">Example: "(object obj) => Debug.Log("This will be fired from the MainThread: " + System.Threading.Thread.CurrentThread.Name + "\nObject: " + obj.toString())"</param>
 /// <param name="safeMode">Executes all the computations within try-catch events, logging it the message + stacktrace</param>
 /// <returns>After the MainThread has executed the "dispatchCall" (and the worker-thread has been waiting), it will return whatever the dispatchCall returns to the worker-thread</returns>
 public static object DispatchToMainThreadReturn(ThreadDispatchDelegateReturn dispatchCall, bool safeMode = true)
 {
     if (MainThreadWatchdog.CheckIfMainThread())
     {
         if (dispatchCall != null)
         {
             return(dispatchCall());
         }
     }
     else
     {
         ThreadDispatchAction action = new ThreadDispatchAction();
         lock (dispatchActions) { dispatchActions.Add(action); }
         action.Init(dispatchCall, safeMode); //Puts the Thread to sleep while waiting for the action to be invoked.
         return(action.dispatchExecutionResult);
     }
     return(null);
 }
Exemplo n.º 9
0
 public static T DispatchToMainThreadReturn <T>(CallBackReturn <T> dispatchCall, bool safeMode = true)
 {
     if (MainThreadWatchdog.CheckIfMainThread())
     {
         if (dispatchCall != null)
         {
             return(dispatchCall());
         }
     }
     else
     {
         ThreadDispatchAction <T> t = new ThreadDispatchAction <T>();
         dispatchActions.Enqueue(t);
         t.Init(dispatchCall, safeMode);
         return(t.dispatchExecutionResult2);
     }
     return(default(T));
 }
Exemplo n.º 10
0
 public static object DispatchToMainThreadReturn <T>(CallBackArgRturn <T> dispatchCall, T dispatchArgument, bool safeMode = true)
 {
     if (MainThreadWatchdog.CheckIfMainThread())
     {
         if (dispatchCall != null)
         {
             return(dispatchCall(dispatchArgument));
         }
     }
     else
     {
         ThreadDispatchAction <T> t = new ThreadDispatchAction <T>();
         dispatchActions.Enqueue(t);
         t.Init(dispatchCall, dispatchArgument, safeMode);
         return(t.dispatchExecutionResult);
     }
     return(null);
 }
        public static void DispatchToMainThread <T>(CallBackArg <T> dispatchCall, T dispatchArgument, bool waitForExecution = false, bool safeMode = true)
        {
            bool flag = MainThreadWatchdog.CheckIfMainThread();

            if (flag)
            {
                bool flag2 = dispatchCall != null;
                if (flag2)
                {
                    dispatchCall(dispatchArgument);
                }
            }
            else
            {
                ThreadDispatchAction <T> threadDispatchAction = new ThreadDispatchAction <T>();
                MainThreadDispatcher.dispatchActions.Enqueue(threadDispatchAction);
                threadDispatchAction.Init(dispatchCall, dispatchArgument, waitForExecution, safeMode);
            }
        }