コード例 #1
0
ファイル: UnityTask.cs プロジェクト: NoxHarmonium/unity-tools
        /// <summary>
        /// Initializes a new instance of the <see cref="UnityTask`1"/> class which wraps
        /// an action, automatically running it on a new thread. All uncaught exceptions 
        /// thrown in the spawned thread will automatically trigger Task.Reject().
        /// </summary>
        /// <param name="taskAction">The delegate that will be executed on a seperate thread.</param>
        /// <param name="dispatchOnUnityThread">If set to <c>true</c> than dispatch callbacks on unity thread.</param>
        public UnityTask(UnityTaskAutoThreadDelegate taskAction, IDispatcher dispatcher = null)
        {
            _waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
            _dispatcher = dispatcher;

            _thread = new Thread( () =>
            {
                try
                {
                    taskAction(this);
                }
                catch (Exception e)
                {
                    this.Reject(e);
                }
            });
            _thread.Start();
        }
コード例 #2
0
ファイル: UnityTask.cs プロジェクト: NoxHarmonium/unity-tools
        /// <summary>
        /// Initializes a new instance of the <see cref="UnityTask`1"/> class which wraps
        /// an action, automatically running it on a new thread. All uncaught exceptions
        /// thrown in the spawned thread will automatically trigger Task.Reject().
        /// </summary>
        /// <param name="taskAction">The delegate that will be executed on a seperate thread.</param>
        /// <param name="dispatchOnUnityThread">If set to <c>true</c> than dispatch callbacks on unity thread.</param>
        public UnityTask(UnityTaskAutoThreadDelegate taskAction, IDispatcher dispatcher = null)
        {
            _waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
            _dispatcher = dispatcher;

            _thread = new Thread(() =>
            {
                try
                {
                    taskAction(this);
                }
                catch (Exception e)
                {
                    this.Reject(e);
                }
            });
            _thread.Start();
        }