/// <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); } }
/// <summary> /// Fires ExceptionCaught event /// </summary> /// <param name="ctx">The StageWorkerContext</param> private void OnException(StageWorkerContext ctx) { Log.Error("Caught exception in ThreadPool", ctx.Exception); if (ExceptionCaught == null) { return; } ExceptionCaught(this, ctx); }
/// <summary> /// Queue work item to the pool. The work item /// will run right away if a thread is available /// other wise it will be queued. Exact semantics /// will depend on implementation /// </summary> /// <param name="context">the stage's worker /// execution context</param> public override void QueueWork(StageWorkerContext context) { SmartThreadPool.QueueWorkItem(StageWorkerThread, context); }
/// <summary> /// Queue work item to the pool. The work item /// will run right away if a thread is available /// other wise it will be queued. Exact semantics /// will depend on implementation /// </summary> /// <param name="context">the stage's worker /// execution context</param> public abstract void QueueWork (StageWorkerContext context);
/// <summary> /// Queue work item to the pool. The work item /// will run right away if a thread is available /// other wise it will be queued. Exact semantics /// will depend on implementation /// </summary> /// <param name="context">the stage's worker /// execution context</param> public override void QueueWork(StageWorkerContext context) { ThreadPoolUtil.QueueUserWorkItem(StageWorkerThread, context); }