Exemple #1
0
        protected void StartTask(PersistentSchedulerTask schedule)
        {
            //run taks
            lock (runningTasks) {
                log.Debug("Creating task queue for " + schedule);

                var task = taskFactory.StartNew((s) => {
                    var ss                = s as PersistentSchedulerTask;
                    ss.ScriptFinished    += OnScriptFinished;
                    ss.ScriptStarted     += OnScriptStarted;
                    ss.ScriptCustomEvent += OnScriptCustomEvent;
                    ss.TaskFinished      += OnTaskFinished;
                    ss.TaskStarted       += OnTaskStarted;
                    log.Debug("Starting: " + ss);
                    ss.Execute(container);
                    return(ss);
                }, schedule)
                           .ContinueWith((s) =>
                {
                    try
                    {
                        var ss                = s.Result as PersistentSchedulerTask;
                        ss.ScriptFinished    -= OnScriptFinished;
                        ss.ScriptStarted     -= OnScriptStarted;
                        ss.TaskFinished      -= OnTaskFinished;
                        ss.ScriptCustomEvent -= OnScriptCustomEvent;
                        ss.TaskStarted       -= OnTaskStarted;
                        runningTasks.Remove(ss);
                        log.Debug("Finished: " + ss);
                        CheckQueue(this);
                    }
                    catch (Exception ex)
                    {
                        log.Error("Unhandler error in schedule task", ex);
                    }
                });
                runningTasks.Add(schedule);
            }
        }
        protected void StartTask(PersistentSchedulerTask schedule)
        {
            //run taks
            lock(runningTasks) {

                log.Debug("Creating task queue for " + schedule);

                var task = taskFactory.StartNew((s) => {
                    var ss = s as PersistentSchedulerTask;
                    ss.ScriptFinished += OnScriptFinished;
                    ss.ScriptStarted += OnScriptStarted;
                    ss.ScriptCustomEvent += OnScriptCustomEvent;
                    ss.TaskFinished += OnTaskFinished;
                    ss.TaskStarted += OnTaskStarted;
                    log.Debug("Starting: " + ss);
                    ss.Execute(container);
                    return ss; 
                },schedule)
                .ContinueWith((s) =>
                {
                    try
                    {
                        var ss = s.Result as PersistentSchedulerTask;
                        ss.ScriptFinished -= OnScriptFinished;
                        ss.ScriptStarted -= OnScriptStarted;
                        ss.TaskFinished -= OnTaskFinished;
                        ss.ScriptCustomEvent -= OnScriptCustomEvent;
                        ss.TaskStarted -= OnTaskStarted;
                        runningTasks.Remove(ss);
                        log.Debug("Finished: " + ss);
                        CheckQueue(this);
                    }
                    catch (Exception ex)
                    {
                        log.Error("Unhandler error in schedule task", ex);
                    }
                });
                runningTasks.Add(schedule);
            }
        }