Beispiel #1
0
        /// <summary>
        /// Push event to this stage. Work may run
        /// on callers thread, or a different one depending on
        /// the RunInCallerContext property
        /// </summary>
        /// <param name="callback">Callback</param>
        /// <param name="e">Event being queued</param>
        protected void PushEvent
            (StageWorkerCallback callback, StageEvent e)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug("Pushing event, current Stage is ["
                          + this + "], e is [" + e + "]");
            }


            var swc = new StageWorkerContext(callback, e);

            if (StageThreadPool == null || RunInCallerContext ||
                e.RunSynchronous)
            {
                // run in caller context
                try { callback.Invoke(e); }
                catch (Exception ex)
                {
                    swc.Exception = ex;
                    FireStageEvent(new StageExceptionEvent(swc));
                }
            }
            else
            {
                // push context
                StageThreadPool.QueueWork(swc);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Ctor with init
 /// </summary>
 /// <param name="cb">The worker callback</param>
 /// <param name="e">The state used by worker</param>
 public StageWorkerContext
     (StageWorkerCallback cb, StageEvent e)
 {
     StageWorkerCallback = cb;
     StageWorkerEvent    = e;
 }