Exemple #1
0
        public static Action WithEnv <T>(this Func <T> handler, TaskEnv env, Result <T> result)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            System.Diagnostics.StackTrace stacktrace = DebugUtil.GetStackTrace();
            env.Acquire();
            return(() => {
                try {
                    T response = default(T);
                    Exception exception = env.InvokeNow(() => {
                        response = handler();
                    });
                    env.Release();

                    // check if a result object was provided
                    if (result != null)
                    {
                        if (exception != null)
                        {
                            result.Throw(exception);
                        }
                        else
                        {
                            result.Return(response);
                        }
                    }
                } catch (Exception e) {
                    _log.ErrorExceptionMethodCall(e, "Execution failed for state wrapped handler", stacktrace, handler.Method.Name);
                }
            });
        }
 void ITaskTimerOwner.AddToQueue(TaskTimer timer, TaskEnv env, TaskTimerStatus next)
 {
     env.Acquire();
     if (timer.Env != null)
     {
         timer.Env.Release();
     }
     if (_running)
     {
         lock (_queue) {
             timer.Env = env;
             timer.SetStatus(next);
             _queue.Enqueue(timer);
         }
     }
     else
     {
         env.Release();
         timer.Env = null;
         timer.SetStatus(TaskTimerStatus.Done);
     }
 }
 void ITaskTimerOwner.AddToPending(TaskTimer timer, TaskEnv env, TaskTimerStatus next)
 {
     env.Acquire();
     if (timer.Env != null)
     {
         timer.Env.Release();
     }
     if (_running)
     {
         lock (_pending) {
             timer.Env = env;
             timer.SetStatus(next);
             _pending[timer] = null;
         }
     }
     else
     {
         env.Release();
         timer.Env = null;
         timer.SetStatus(TaskTimerStatus.Done);
     }
 }