Exemple #1
0
        internal void Execute()
        {
            CreateEnvironment();

            _completedSynchronouslyThreadId = Thread.CurrentThread.ManagedThreadId;
            try
            {
                _appContext.AppFunc(_env)
                // We can't use Then/Catch here because they would re-enter the sync context.
                // The async callback must be called outside of the sync context.
                .ContinueWith(appTask =>
                {
                    if (appTask.IsFaulted)
                    {
                        Complete(ErrorState.Capture(appTask.Exception));
                    }
                    else if (appTask.IsCanceled)
                    {
                        Complete(ErrorState.Capture(new TaskCanceledException(appTask)));
                    }
                    else
                    {
                        OnEnd();
                    }
                });
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                _completedSynchronouslyThreadId = Int32.MinValue;
            }
        }