Exemplo n.º 1
0
        public void work()
        {
            TaskWrapper TaskWrapper = null;

            while (true)
            {
                //Retrieves executable tasks
                TaskWrapper = getCanExecuteTask();

                if (null == TaskWrapper)
                {
                    try
                    {
                        Thread.Sleep(5);
                    }
                    catch (ThreadInterruptedException)
                    {
                        continue;
                    }
                    //Continue to retrieve executable tasks
                    continue;
                }

                try
                {
                    if (null == TaskWrapper || null == TaskWrapper.CurrentTask)
                    {
                        continue;
                    }

                    if (TaskWrapper.canExecute)
                    {
                        try
                        {
                            TaskWrapper.CurrentTask.run();
                        }
                        catch (System.Exception ex)
                        {
                            LogManager.WriteLog(LogTypes.Error, string.Format("Asynchronous scheduling task execution error: {0}", ex));
                        }
                    }


                    //If it is a cycle of the implementation of the task
                    if (TaskWrapper.Periodic > 0 && TaskWrapper.canExecute)
                    {
                        //Set the next execution time
                        TaskWrapper.resetStartTime();
                        executor.addTask(TaskWrapper);
                        TaskWrapper.addExecuteCount();
                    }
                }
                catch (System.Exception ex)
                {
                    DataHelper.WriteFormatExceptionLog(ex, "Asynchronous scheduling task execution exception", false);
                }
            }
        }
Exemplo n.º 2
0
        public void work()
        {
            TaskWrapper TaskWrapper = null;

            for (;;)
            {
                TaskWrapper = this.getCanExecuteTask();
                if (null == TaskWrapper)
                {
                    try
                    {
                        Thread.Sleep(5);
                    }
                    catch (ThreadInterruptedException)
                    {
                    }
                }
                else
                {
                    try
                    {
                        if (TaskWrapper != null && null != TaskWrapper.CurrentTask)
                        {
                            if (TaskWrapper.canExecute)
                            {
                                try
                                {
                                    TaskWrapper.CurrentTask.run();
                                }
                                catch (Exception ex)
                                {
                                    LogManager.WriteLog(LogTypes.Error, string.Format("异步调度任务执行错误: {0}", ex), null, true);
                                }
                            }
                            if (TaskWrapper.Periodic > 0L && TaskWrapper.canExecute)
                            {
                                TaskWrapper.resetStartTime();
                                this.executor.addTask(TaskWrapper);
                                TaskWrapper.addExecuteCount();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DataHelper.WriteFormatExceptionLog(ex, "异步调度任务执行异常", false, false);
                    }
                }
            }
        }