Пример #1
0
 public void append(BackgroundWorkerItem item, Object[] parameters, TimeSpan timeout, ApartmentState apartmentState, ThreadPriority priority)
 {
     StackItem sItem = new StackItem();
     sItem.bWItem = item;
     sItem.parameters = parameters;
     sItem.timeout = timeout;
     sItem.apartmentState = apartmentState;
     sItem.priority = priority;
     //
     this._methodStack.Add(sItem);
 }
Пример #2
0
        public void append(BackgroundWorkerItem item, Object[] parameters, TimeSpan timeout, ApartmentState apartmentState, ThreadPriority priority)
        {
            StackItem sItem = new StackItem();

            sItem.bWItem         = item;
            sItem.parameters     = parameters;
            sItem.timeout        = timeout;
            sItem.apartmentState = apartmentState;
            sItem.priority       = priority;
            //
            this._methodStack.Add(sItem);
        }
Пример #3
0
 public void append(BackgroundWorkerItem item, Object[] parameters, TimeSpan timeout)
 {
     this.append(item, parameters, timeout, ApartmentState.Unknown, ThreadPriority.Normal);
 }
Пример #4
0
 public void append(BackgroundWorkerItem item, Object[] parameters, TimeSpan timeout)
 {
     this.append(item, parameters, timeout, ApartmentState.Unknown, ThreadPriority.Normal);
 }
Пример #5
0
        /// <summary>
        /// Führt die Methode mittels Delegate und übergebenen Parametern, die in der festgesetzen Zeit ausgeführt wurde.
        /// </summary>
        /// <param name="d">Auszuführendes Delegate</param>
        /// <param name="parameters">Zu übergebende Paramter für das Delegate</param>
        /// <param name="timeout">Zu erwartende Höchstzeit, bevor die Ausführung des Delegates abgebrochen wird</param>
        /// <returns>True, wenn die Ausführung des Delegates vor dem Timeout zu Ende gegangen ist. False wenn das Timeout überschritten wurde.</returns>
        public bool run(BackgroundWorkerItem item, object[] parameters, TimeSpan timeout)
        {
            this._item = item;
            //
            bool resetTimeout = false;
            //
            Worker w = new Worker(item, parameters, this._evnt);

            w.Alive += delegate(Object sender, EventArgs e) {
                resetTimeout = true;
            };
            this._thread = new Thread(new ThreadStart(w.run));

            // init
            this._abort  = false;
            this._cancel = false;

            this._evnt.Reset();

            this._thread.Priority = this.ThreadPriority;
            this._thread.SetApartmentState(this.ApartmentState);
            this._thread.Start();
            //
            for (int i = 0; true; i++)
            {
                bool waitOne = this._evnt.WaitOne(INTERVAL, false);
                if (waitOne)
                {
                    this._thread = null;
                    //
                    if (this._cancel)
                    {
                        log.Debug("run - cancel completed");
                        return(false);
                    }
                    //
                    if (this._abort)
                    {
                        log.Debug("run - abort completed");
                        return(false);
                    }
                    //
                    return(true);
                }
                //
                // fire interval tick event
                if (this.IntervalTick != null)
                {
                    this.IntervalTick(this, new EventArgs());
                }
                // check for reset timeout
                if (resetTimeout)
                {
                    resetTimeout = false;
                    i            = -1;
                }
                // check abort or timeout
                if ((timeout.TotalMilliseconds / INTERVAL) == i)
                {
                    this._thread.Abort();
                    this._thread = null;
                    //
                    throw new TimeoutException();
                }
            }
        }
Пример #6
0
 public Worker(BackgroundWorkerItem item, object[] parameters, AutoResetEvent evnt)
 {
     this._item       = item;
     this._parameters = parameters;
     this._evnt       = evnt;
 }
Пример #7
0
 public Worker(BackgroundWorkerItem item, object[] parameters, AutoResetEvent evnt)
 {
     this._item = item;
     this._parameters = parameters;
     this._evnt = evnt;
 }
Пример #8
0
        /// <summary>
        /// Führt die Methode mittels Delegate und übergebenen Parametern, die in der festgesetzen Zeit ausgeführt wurde.
        /// </summary>
        /// <param name="d">Auszuführendes Delegate</param>
        /// <param name="parameters">Zu übergebende Paramter für das Delegate</param>
        /// <param name="timeout">Zu erwartende Höchstzeit, bevor die Ausführung des Delegates abgebrochen wird</param>
        /// <returns>True, wenn die Ausführung des Delegates vor dem Timeout zu Ende gegangen ist. False wenn das Timeout überschritten wurde.</returns>
        public bool run(BackgroundWorkerItem item, object[] parameters, TimeSpan timeout)
        {
            this._item = item;
            //
            bool resetTimeout = false;
            //
            Worker w = new Worker(item, parameters, this._evnt);
            w.Alive += delegate(Object sender, EventArgs e) {
                resetTimeout = true;
            };
            this._thread = new Thread(new ThreadStart(w.run));

            // init
            this._abort = false;
            this._cancel = false;

            this._evnt.Reset();

            this._thread.Priority = this.ThreadPriority;
            this._thread.SetApartmentState(this.ApartmentState);
            this._thread.Start();
            //
            for (int i = 0; true; i++) {
                bool waitOne = this._evnt.WaitOne(INTERVAL, false);
                if (waitOne) {
                    this._thread = null;
                    //
                    if (this._cancel) {
                        log.Debug("run - cancel completed");
                        return false;
                    }
                    //
                    if (this._abort) {
                        log.Debug("run - abort completed");
                        return false;
                    }
                    //
                    return true;
                }
                //
                // fire interval tick event
                if (this.IntervalTick != null) {
                    this.IntervalTick(this, new EventArgs());
                }
                // check for reset timeout
                if (resetTimeout) {
                    resetTimeout = false;
                    i = -1;
                }
                // check abort or timeout
                if ((timeout.TotalMilliseconds / INTERVAL) == i) {
                    this._thread.Abort();
                    this._thread = null;
                    //
                    throw new TimeoutException();
                }
            }
        }