Пример #1
0
        protected Task RunAsync(ThreadPool threadPool)
#endif
        {
            /*
             * The coroutine approach doesnt work:
             * Unity executes the coroutine in the update cycle (main thread) so,
             * if there is a Wait in the Task (most likely) the main thread will get frozen
             */
            //Dispatcher.instance.LaunchCoroutine(RunCoroutine());
            Exception = null;
            m_state   = TState.Running;
#if UNITY_WEBGL
            U3D.Threading.Dispatcher.instance.ToMainThread(() =>
#else
            m_runThread = threadPool.QueueAction(() =>
#endif
            {
                try
                {
                    m_action();
                    CheckAbort();
                    m_state = TState.Successful;
                }
                catch (TaskAbortException)
                {
                    m_state = TState.Aborted;
                }
#if !(UNITY_WSA && !ENANLE_IL2CPP) && !UNITY_EDITOR
                catch (System.Threading.ThreadAbortException)
                {
                    m_state = TState.Aborted;
                }
#endif
                catch (Exception e)
                {
                    this.Exception = new AggregateException(e);
                    m_state        = TState.Faulted;
                }
                finally
                {
#if !UNITY_WEBGL
                    m_runThread = null;
#endif
                }
            });
            return(this);
        }
Пример #2
0
        protected Task RunAsync(ThreadPool threadPool)
#endif
        {
            /*
             * The coroutine approach doesnt work:
             * Unity executes the coroutine in the update cycle (main thread) so, 
             * if there is a Wait in the Task (most likely) the main thread will get frozen
             */
            //Dispatcher.instance.LaunchCoroutine(RunCoroutine());
            Exception = null;
            m_state = TState.Running;
#if UNITY_WEBGL
            U3D.Threading.Dispatcher.instance.ToMainThread(() =>
#else
            m_runThread = threadPool.QueueAction(() =>
#endif
            {
                try
                {
					m_action();
					m_state = TState.Successful;
                }
				catch (System.Threading.ThreadAbortException)
				{
					m_state = TState.Aborted;
				}
				catch (Exception e)
                {
					this.Exception = new AggregateException(e);
                    m_state = TState.Faulted;
                }
				finally
				{
#if !UNITY_WEBGL
                    m_runThread = null;
#endif
				}
            });
            return this;
        }