Ejemplo n.º 1
0
        internal async Task RerunAsync(IFrameExecutionContext context)
        {
            int       runCount  = Interlocked.Increment(ref _runCount);
            IJSHandle success   = null;
            Exception exception = null;

            try
            {
                success = await _task(context).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (_terminated || runCount != _runCount)
            {
                if (success != null)
                {
                    await success.DisposeAsync().ConfigureAwait(false);
                }

                return;
            }

            if (exception == null &&
                await context.EvaluateAsync <bool>("s => !s", success)
                .ContinueWith(task => task.IsFaulted || task.Result, TaskScheduler.Default)
                .ConfigureAwait(false))
            {
                if (success != null)
                {
                    await success.DisposeAsync().ConfigureAwait(false);
                }

                return;
            }

            if (exception?.Message.Contains("Execution context was destroyed") == true)
            {
                _ = RerunAsync(context);
                return;
            }

            if (exception?.Message.Contains("Cannot find context with specified id") == true)
            {
                return;
            }

            if (exception != null)
            {
                _taskCompletion.TrySetException(exception);
            }
            else
            {
                _taskCompletion.TrySetResult(success);
            }

            DoCleanup();
        }
Ejemplo n.º 2
0
        private void SetContext(ContextType contextType, IFrameExecutionContext context)
        {
            var data = _contextData[contextType];

            data.Context = context;

            if (context != null)
            {
                data.ContextTsc.TrySetResult(context);

                foreach (var rerunnableTask in data.RerunnableTasks)
                {
                    _ = rerunnableTask.RerunAsync(context);
                }
            }
            else
            {
                data.ContextTsc = new TaskCompletionSource <IFrameExecutionContext>();
            }
        }