在线程中分配会话变量 [英] Assign Session variables in Threading

查看:119
本文介绍了在线程中分配会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有page1.aspx,在页面加载中,我有将在Thread中作为
调用的函数

如果(isEmail ==  1 )
           {
               //  objmyClass.deliveryType =电子邮件"; 
               线程cwpThread = new Thread(new ParameterizedThreadStart(ProcessMyList));   
               abc.Start(" );   

           }
           如果(isFax ==  1 )
           {
               //  objmyClass.deliveryType ="fax"; 
               线程abc =新线程(新ParameterizedThreadStart(ProcessMyList));   
               abc.Start(" );   
           } 



在上面的代码中,ProcessMyList将在线程&中被调用.在此函数中,我将会话值分配为

 Session ["  ] = " ;
           会话[" ] = "  4321"; 


.但是,当我导航到另一个页面时,我无法读取这些会话值.

在这方面帮助我.

感谢

解决方案

可用于所有线程的状态是静态值.当客户端发出新请求时,将为其创建一个新线程,并创建一个HttpContext实例.但是,当您创建新线程时,状态不会自动传递给它.这是一件好事,因为您的大多数状态应该仅特定于当前线程.


您是否使用了调试器来确保甚至对其进行了设置?

Hi,

I have page1.aspx, in page load I have function which will be called in Thread as

if (isEmail == 1)
           {
               //objmyClass.deliveryType = "email";
               Thread cwpThread = new Thread(new ParameterizedThreadStart(ProcessMyList));
               abc.Start("email");

           }
           if (isFax == 1)
           {
               //objmyClass.deliveryType = "fax";
               Thread abc = new Thread(new ParameterizedThreadStart(ProcessMyList));
               abc.Start("fax");
           }



In the above code ProcessMyList will be called in thread & in this function I am assigning session values as

Session["EmailFileIds"] = "1234";
           Session["FaxFileIds"] = "4321";


. But when I navigate to another page, I am not able to read these session values.

help me in this regard.

Thanks

解决方案

The state that is available to all threads are the static values. When a new request is made by a client a new thread is created for it and an instance of HttpContext as well. But when you create a new thread the state isn''t passed to it automatically. And this is a good thing as most of your state should be specific only to the current thread.


Have you used the debugger to make sure they''re even being set?


这篇关于在线程中分配会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆