How to use ExecutionContext to provide a stream of my own context?

Update:

Found a similar question .

I want to implement some services following the AmbientContext design pattern for our ASP.NET application.
For example, I want the username (for example, Thread.CurrentPrincipal) to be set once at the very beginning of the request and thread processing between threads when performing asynchronous operations.
Thus, I need to attach the data to the ExecutionContext and then detach it while processing the request.

Unfortunately, I have no idea how to do this.

There is a small hint in the documentation :

Internally, an ExecutionContext stores all the data that is associated with a LogicalCallContext. This allows you to use LogicalCallContext data for distribution when copying and passing an ExecutionContext.

+4
source share
1 answer

I had the same question. As a result, I found the CallContext class , which can be used using the LogicalGetDataand methods LogicalSetData. Here is a very good article with examples discussing how to use this class.

+1
source

Source: https://habr.com/ru/post/1542898/