如何HttpContext.Current工作在多线程环境中?

编程入门 行业动态 更新时间:2024-10-22 11:23:28
本文介绍了如何HttpContext.Current工作在多线程环境中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我在想asp究竟怎么能范围静态属性,当(据我所知)asp是多线程的。

So I'm left wondering how exactly asp is able to scope a static property, when (to my knowledge) asp is multi-threaded.

  • 有一种理论去了ASP.NET家伙保持为每个请求不同的AppDomain ...但似乎并不可行。
  • 另一种理论认为,该.Current方法着眼于当前的线程,然后使用它来查找一些哈希表中的HTTP上下文(或其他静态存储机制)。

无论哪种方式,它似乎非常有用的技术。我想利用它,但绝对不希望被调试共享状态的错误: - /

Either way, it's a technique that seems really useful ... I'd like to utilize it, but definitely don't want to be debugging shared state bugs :-/

推荐答案

什么马克说是最简单最有可能为你所追求的,但实际上ASP.NET是有点比更复杂的东西说ThreadStatic呢,因为单一的请求实际上可以通过多线程处理..什么,我相信与ASP.NET的情况是,正在执行的线程明确地被告知要切换上下文,当然主机环境是调度线程,它有它的需求的HttpContext执行上下文中,因此认定一个线程,告诉它应该运行在上下文中的线程..然后把它发送的道路上。

What Marc says is the easiest most likely for what you are after, however ASP.NET is actually somewhat more complicated than what say ThreadStatic does, because single requests actually can be processed by multiple threads.. what I believe happens with ASP.NET is that the executing thread explicitely is told to switch context, of course the hosting environment is scheduling the threads and it has context of which httpcontext needs executing, so it finds a thread, tells the thread which context it should run in.. then sends it off on its way.

因此​​,解决办法真的是不是所有的pretty可悲的是,那里的threadstatic要简单得多,可能需要适合的95%的时间。

So the solution really isn't all that pretty sadly, where as threadstatic is much simpler and probably suits needs 95% of the time.

更多推荐

如何HttpContext.Current工作在多线程环境中?

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

发布评论

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

>www.elefans.com

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