Can I access sessions in background thread?
开发者_如何转开发How can i access my project sessions in background thread in my c#.net webapplication?
it gives me session value = null.
Any idea?
Threads in the thread pool are managed by the system. These threads are not bound to the current request. Therefore, Session is not available for them.
session lost when multithreading though
You have to be very careful about using background threads with ASP.NET. By the time the thread executes, the "current" request will probably be over. This means you can't access the page, or the request, or anything interesting.
You can't access the session but you could share your data the same way, using: HttpRuntime.Cache
There are a few things to keep in mind though: unlike session, cache do expire. Also the cache is shared between all web users.
精彩评论