C# 如何在线程(后台进程)C中使用会话变量#

C# 如何在线程(后台进程)C中使用会话变量#,c#,asp.net,multithreading,session,caching,C#,Asp.net,Multithreading,Session,Caching,我在线程(后台进程)内的会话中存储数据时遇到问题 这是由于对象引用错误引起的 我也使用了HttpRuntime.Cache,但当我在两个系统中运行时,它会产生相同的结果,根据输入应该不同(我认为它覆盖了值) 我搜索了web,知道httpcontext不能在线程中工作 所以,请告诉我这个问题的解决方案。谢谢,但我需要将Datatable存储到会话变量 var data= SynchronizationContext.Current; Task t = Task.Run(() => {

我在线程(后台进程)内的会话中存储数据时遇到问题

这是由于对象引用错误引起的

我也使用了HttpRuntime.Cache,但当我在两个系统中运行时,它会产生相同的结果,根据输入应该不同(我认为它覆盖了值)

我搜索了web,知道httpcontext不能在线程中工作


所以,请告诉我这个问题的解决方案。

谢谢,但我需要将Datatable存储到会话变量
var data= SynchronizationContext.Current;


Task t = Task.Run(() => {

    string sessionValue = null;

    data.Post(() => {

        sessionValue = HttpContext.Current.Session["value"];
    }


});
var data= SynchronizationContext.Current;


Task t = Task.Run(() => {

    string sessionValue = null;

    data.Post(() => {

        sessionValue = HttpContext.Current.Session["value"];
    }


});