Пример #1
0
        public void WakeUp(object sender, object eventArgs)
        {
            DateTime now = DateTime.Now;

            if (_isWakeUp)
            {
                return;
            }
            _isWakeUp = true;
            try
            {
                foreach (var taskConfig in _taskConfig)
                {
                    bool isAllComplete = taskConfig.ThreadPool.TrueForAll(item => !item.IsAlive);
                    if (isAllComplete)
                    {
                        taskConfig.ThreadPool.Clear();
                    }
                    if (taskConfig.NextDateTime.HasValue && taskConfig.NextDateTime <= DateTime.Now)
                    {
                        string executionId = Common.MD5(Clock.GetTimeStamp(true) + taskConfig.TargetType.Name);
                        if (taskConfig.ThreadPool.Count > 0 && !taskConfig.TargetType.IsAsync)
                        {
                            continue;
                        }
                        taskConfig.LastRunTime = now;
                        TaskThread thread = taskConfig.TargetType.Run(executionId);
                        taskConfig.ThreadPool.Add(thread);
                        taskConfig.GoNext();
                    }
                }
            }
            catch (Exception ex)
            {
                EventRouter.GetInstance().FireEvent("Error_Occurred", "CronTab",
                                                    "Fatal error:" + ex.GetBaseException().Message + "\n\t" + ex.GetBaseException().StackTrace);
            }
            finally
            {
                _isWakeUp = false;
            }
        }
Пример #2
0
        public TaskThread Run(string executionId)
        {
            TaskThread taskThread = new TaskThread(new Thread((o) =>
            {
                try
                {
                    Method.Invoke(executionId);
                }
                catch (Exception ex)
                {
                    EventRouter.GetInstance().FireEvent("Warn_Occurred", this,
                                                        $"Execute task {Method} failed: {(ex.InnerException == null ? ex.Message : ex.InnerException.Message)}\nStack trace:\n{ex.StackTrace}");
                }
            }), MaximumExecuteTime, executionId)
            {
                CreateTime = DateTime.Now
            };

            return(taskThread);
        }