示例#1
0
    private void _processQueue() {
      if (this._isActive) return;
      if (this.Count > 0) {
        this._isActive = true;

        CThreadsQueueItem nextItem = null;
        lock (this.queue) {
          nextItem = this.queue.Dequeue();
        }

        this._activeThead = new Thread(new ParameterizedThreadStart((c) => {
          var nItem = c as CThreadsQueueItem;
          try {
            try {
              var args = new OnBeforeActionEventArgs { Cancel = false, item = nItem };
              this._doOnBeforeAction(args);
              if (!args.Cancel) {
                if ((nItem != null) && (nItem.action != null))
                  nItem.action();
              }
            } catch (Exception ex) {
              this._doOnErrorAction(new OnErrorActionEventArgs { item = nItem, exception = ex });
            }
          } finally {
            try {
              this._doOnAfterAction(new OnAfterActionEventArgs { item = nItem });
            } catch (Exception ex) {
              this._doOnErrorAction(new OnErrorActionEventArgs { item = nItem, exception = ex });
            }


            this._isActive = false;
            this._processQueue();
          }
        }));
        this._activeThead.Name = nextItem.name;
        this._activeThead.Start(nextItem);
      }
    }
示例#2
0
 private void _doOnBeforeAction(OnBeforeActionEventArgs args) {
   var hndlr = this.OnBeforeAction;
   if (hndlr != null)
     hndlr(this, args);
 }