Example #1
0
        public Func <Task> CreateAction(Action action)
        {
            Func <Task> resultAction = async() =>
            {
                var actionId = Interlocked.Increment(ref this.actionCounter);
                try
                {
                    await this.semaphore.WaitAsync();

                    Logger.Trace($"Transition [{actionId}] started");
                    await WaitForFinish();

                    // not cancellable, so new cancellation token isn't created
                    action();
                    this.currentTask = Task.CompletedTask;
                    Logger.Trace($"Transition [{actionId}] finished");
                }
                catch (Exception ex)
                {
                    Logger.Error($"Error on handling action [{actionId}]: " + ex);
                }
                finally
                {
                    this.semaphore.Release();
                }
            };

#if DEBUG
            resultAction = ReflectionsHelper.WrapActionWithName(resultAction, action.Method.Name);
#endif

            return(resultAction);
        }
 public void Error(string message, Exception error = null)
 {
     Logger.Error($"{message} {error}");
 }