每次等待完成“选项”时是否使用 ThreadStatic 并设置上下文?还有其他方法吗?
public async void Test()
{
// This is in Thread 1
Foo foo = new Foo();
Context.context = "context1"; // This is ThreadStatic
string result = await foo.CallAsynx();
// This is most likely Thread 2
Context.context = "context1"; // This might be a different thread and so resetting context
}
如果我不想使用 ThreadStatic,现在还有另一种方法吗?