Exemple #1
0
 protected StatefulComponentBase()
 {
     StateChanged = (_, eventKind) => {
         if ((eventKind & StateHasChangedTriggers) == 0)
         {
             return;
         }
         using var suppressing = ExecutionContextExt.SuppressFlow();
         Task.Run(() => this.StateHasChangedAsync(BlazorCircuitContext));
     };
 }
Exemple #2
0
    public Task Run(
        CommandContext context, bool isolate,
        CancellationToken cancellationToken = default)
    {
        // Task.Run is used to call RunInternal to make sure parent
        // task's ExecutionContext won't be "polluted" by temp.
        // change of CommandContext.Current (via AsyncLocal).
        if (!isolate)
        {
            return(Task.Run(() => RunInternal(context, cancellationToken), default));
        }

        using var _ = ExecutionContextExt.SuppressFlow();
        return(Task.Run(() => RunInternal(context, cancellationToken), default));
    }
Exemple #3
0
    protected virtual void Dispose(bool disposing)
    {
        if (IsDisposed || !disposing)
        {
            return;
        }

        IsDisposed            = true;
        using var suppressing = ExecutionContextExt.SuppressFlow();
        _ = Task.Run(async() => {
            using (await AsyncLock.Lock().ConfigureAwait(false)) {
                var dbContext = DbContext;
                if (dbContext != null)
                {
                    await dbContext.DisposeAsync().ConfigureAwait(false);
                }
            }
        });
    }
Exemple #4
0
    public Task OnOperationCompleted(IOperation operation)
    {
        if (!StringComparer.Ordinal.Equals(operation.AgentId, AgentInfo.Id.Value)) // Only local commands require notification
        {
            return(Task.CompletedTask);
        }
        var commandContext = CommandContext.Current;

        if (commandContext != null)   // It's a command
        {
            var operationScope = commandContext.Items.Get <DbOperationScope <TDbContext> >();
            if (operationScope == null || !operationScope.IsUsed) // But it didn't change anything related to TDbContext
            {
                return(Task.CompletedTask);
            }
        }
        // If it wasn't command, we pessimistically assume it changed something
        using var _ = ExecutionContextExt.SuppressFlow();
        Task.Run(Notify);
        return(Task.CompletedTask);
    }