System.Threading.Tests.AsyncLocalTests.CaptureAndRestore C# (CSharp) Method

CaptureAndRestore() private method

private CaptureAndRestore ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        public static async Task CaptureAndRestore()
        {
            AsyncLocal<int> local = new AsyncLocal<int>();

            local.Value = 42;

            ExecutionContext ec = ExecutionContext.Capture();

            local.Value = 12;

            ExecutionContext.Run(
                ec,
                _ =>
                {
                    Assert.Equal(local.Value, 42);
                    local.Value = 56;
                },
                null);

            Assert.Equal(local.Value, 12);
        }