/// <summary>
        /// 开始任务
        /// </summary>
        /// <param name="task"></param>
        protected static void Work(object task)
        {
            ITask  curTask = task as ITask;
            object obj     = curTask.Run();

            if (curTask.Callback != null)
            {
                curTask.Callback(obj);
            }

            Stop(Thread.CurrentThread.Name);
        }
Exemple #2
0
        private void ProcessActive()
        {
            if (null != _current)
            {
                _current.Tick(); // heartbeat

                if (_current.IsDone) // if current is done
                {
                    /**
                     * If callback for a job is defined, execute it
                     * */
                    if (null != _current.Callback)
                        _current.Callback(_current);

                    /**
                     * If handler for a SINGLE ITEM FINISHED is defined, execute it
                     * */
                    if (null != SingleFinishedHandler)
                        SingleFinishedHandler(_current);

#if DEBUG
                    if (DebugMode)
                        Debug.Log(string.Format(@"######### Ending job [{0}] after {1} ms #########", _current,
                                                (DateTime.Now.Subtract(_current.StartTime).TotalMilliseconds)));
#endif

                    if (_queued.Count == 0) // if no requests to process
                    {
#if DEBUG
                        if (DebugMode)
                            Debug.Log("### ALL JOBS DONE ###");
#endif
                        /**
                         * If handler for a WHOLE QUEUE is defined, execute it
                         * */
                        if (null != AllFinishedHandler)
                            AllFinishedHandler(_current);

                        IsWorking = false; // set the flag

                        if (AutoUpdate)
                            SystemManager.Instance.UpdateSignal.Connect(UpdateSlot); // disconnect from SystemManager
                    }

                    _current = null; // nullify the reference
                }
            }
        }