I'm using .net core 3.1 api project and i want to access HttpContext inside my Task.Run block. Here is my code:
// before Task.Run my HttpContextAccessor.HttpContext has correct values
Task.Run(async () =>
{
//any other method with await here
var data = await SomeMethod(config); // in that method HttpContextAccessor.HttpContext is null
}, cancellationToken)
In asp.net i could use friendlysynchronizationcontext to deal with it but in .net core there is no synchronization context.
Can someone provide me a solution/explanation how to fix that problem?