With the new async/await keywords in C#, there are now impacts to the way (and when) you use ThreadStatic data, because the callback delegate is executed on a different thre
AsyncLocal
Changing the variable type to AsyncLocal, e.g.,
private static AsyncLocal Secret = new AsyncLocal();
gives the following, desired output:
Started on thread [5]
Secret is [moo moo]
Was on thread [5]
Now on thread [6]
Finished on thread [6]
Secret is [moo moo]