从线程访问HttpContext.Current

编程入门 行业动态 更新时间:2024-10-17 13:31:02
本文介绍了从线程访问HttpContext.Current的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有开始运行的一类叫做SiteCrawler.cs一些方法大约25不同的线程一个C#ASP.NET应用程序。

I have a C# ASP.NET application which starts about 25 different threads running some methods in a class called SiteCrawler.cs.

在 HttpContext.Current.Session 我要保存用户和present它向用户做出的搜索结果,当所有的线程都完成运行。我的问题是, HttpContext.Current 对象是在产生的线程空,因为它不存在那里。

In HttpContext.Current.Session I want to save the result of the search made by the user and present it to the user when all the threads are finished running. My problem is that the HttpContext.Current object is null in the spawned threads because it doesn't exist there.

什么选择我必须保存用户/会话特定的数据,而不当应用程序是多线程的使用,因为限制的会议?

What other options do I have to save user/session specific data without using session because of the limitations when the application is multithreaded?

我试图寻找的#1周围的每一寸找到一个解决方案,但没有任何运气....

I have tried to search around every inch of Stackoverflow to find a solution but without any luck....

推荐答案

在我的应用程序有很多code,它使用 HttpContext.Current 可以和我不修改code。

In my application there are a lot of code that uses HttpContext.Current and I can not modify that code.

worker.DoWork()从下面的示例使用了code。我只好在单独的线程中运行它。

worker.DoWork() from sample below uses that code. And I had to run it in separate thread.

我来到了以下解决方案:

I came to the following solution:

HttpContext ctx = HttpContext.Current; Thread t = new Thread(new ThreadStart(() => { HttpContext.Current = ctx; worker.DoWork(); })); t.Start(); // [... do other job ...] t.Join();

更多推荐

从线程访问HttpContext.Current

本文发布于:2023-11-13 15:04:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584655.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   HttpContext   Current

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!