Пример #1
0
        public virtual void Worker()
        {
            if (AfterComplete != null)
            {
                // We increase this for eacht thread, indicating that work needs to be
                // done still after processing the items
                OwningFlow.IncrementInProcess();
                // Remove this after LastDo
            }

            while (Status == RunStatus.Running)
            {
                try
                {
                    Do();
                }
                catch (ThreadAbortException)
                { /*noop, happens when stopping a flow*/ }
                catch (Exception e)
                {
                    bool stop = true;
                    log.WarnFormat("Exception caught in '{0}'", this.Name);
                    this.OwningFlow.OnError(this, e, e.Data["processedItem"], ref stop);
                    if (stop)
                    {
                        this.Status = RunStatus.Error;
                        this.OwningFlow.Stop();
                        log.Error("Exception is fatal to flow", e);
                    }
                }
            }
            log.DebugFormat("Leaving loop ({0})", this.Name);
            lock (_threads)
            {
                if (_threads.Contains(Thread.CurrentThread))
                {
                    _threads.Remove(Thread.CurrentThread);
                }
                // last one turn off the light, please
                if (_threads.Count == 0)
                {
                    // Last chance for the task to do anything
                    LastDo();
                    if (this.Status == RunStatus.Running || this.Status == RunStatus.Stopping)
                    {
                        this.Status = RunStatus.Stopped;
                    }
                    foreach (var stream in this.OutQueues)
                    {
                        stream.CloseEntrance();
                    }
                }
            }
            if (AfterComplete != null)
            {
                OwningFlow.DecrementInProcess();
            }
            log.InfoFormat("Task '{0}' done", this.Name);
        }
Пример #2
0
 public override void Do()
 {
     OwningFlow.IncrementInProcess();
     TrackStartProcessing();
     Retry.Times(() => Method((IWritableQueue <Tout>)OutQueues[0]), this.Retries, Properties.Settings.Default.RetryWaitMillis, true);
     TrackEndProcessing();
     OwningFlow.DecrementInProcess();
     this.Status = RunStatus.Stopping;
 }