Created
August 13, 2018 09:48
-
-
Save yuessir/d636f67e7e7843557eba0b90876793d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shared variables | |
// private static ThreadLocal<int> local = new ThreadLocal<int>();//output 53000 0; | |
private static AsyncLocal<int> local = new AsyncLocal<int>();//output 53000 53000; | |
private static void Main(string[] args) | |
{ | |
// declare a delegate | |
Action act = async () => | |
{ | |
await RunAsync(); | |
}; | |
// action delegate | |
act(); | |
Console.Read(); | |
} | |
private static async Task RunAsync() | |
{ | |
local.Value = 53000;//set values | |
Console.WriteLine($"Before await:{nameof(local)} = {local.Value}"); | |
await Task.Delay(50); //await 50 miniseconds | |
Console.WriteLine($"After await:{nameof(local)} = {local.Value}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment