Skip to content

API Proposal: ExecutionContext.Run<TContext> overloads #30867

@davidfowl

Description

@davidfowl

Today to run code on a specific ExecutionContext, there's a non-generic Run method that takes a ContextCallback and object state. We should add a generic overload to boxing can be avoided (for e.g. when passing a ValueTuple):

namespace System.Threading
{
    public sealed class ExecutionContext
    {
        // New
        public static void Run<TState>(ExecutionContext context, ContextCallback<TState> callback, ref TState state);

        // Existing
        public static void Run(ExecutionContext executionContext, ContextCallback callback, object? state);
        ...
    }

    // New (it exists but as internal)
    public delegate void ContextCallback<TState>(ref TState state);

    // Existing
    public delegate void ContextCallback(object? state);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions