Reputation: 14088
I am just starting to learn how Task works, and get one interesting case. I have HttpTaskAsyncHandler but I can't get acccess to HttpContext if my code inside ProcessRequestAsync calls to some Task
public class MyAsyncHandler : HttpTaskAsyncHandler, IReadOnlySessionState
{
public override async Task ProcessRequestAsync(HttpContext context)
{
//can use HttpContext here
await MyJob("data");
//can use HttpContext here
}
public async Task MyJob(string data)
{
var func = Task.Factory.StartNew(() => Process(data));
await func;
}
public string Process(string context)
{
**//can't use HttpContext here**
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
}
is it possible to fix ? I understand that Process method would be call in other tread but anyway. Thanks/
Upvotes: 2
Views: 1008
Reputation: 22555
You are correct that HttpContent does not exist inside of your Task, since it is in a separate thread. So you will need to access create a new instance of Elmah inside your Process method(new thread). You can follow the 2nd or 3rd answer in the previous question, Using Elmah in a Console Application to accomplish what you want.
Upvotes: 4