ASP.NET 和 AJAX 线程

发布于 2024-07-13 20:55:14 字数 425 浏览 6 评论 0原文

引用这个问题: ASP.NET 是多线程的(它如何执行requests),这是对线程的正确解释吗: ASP.NET 每个应用程序实例都有一个工作进程。 它是多线程的,使用自己的应用程序池。 大多数线程用于服务(用户)请求。 每个请求(用户会话)都是一个线程。 相应的响应可能是另一个线程。 用户请求以来自 ISAPI 的多个线程的形式出现,ISAPI 本身就是多线程的。

AJAX 不是多线程的。 它使用与非 AJAX 网站相同的线程模型。 页面请求(ajax或非ajax)可能会导致服务器上使用多个线程,但在客户端上仍然是一个线程(浏览器使用单线程)。

Referencing this question: Is ASP.NET multithreaded (how does it execute requests), would this be a correct interpretation of threading:
ASP.NET has one worker process per application instance. It is multi-threaded, using its own application pool. The majority of threads are used for servicing (user) request. Each request (user session) is one thread. The corresponding response may be another thread. User request come as multiple threads from ISAPI, which is itself multi-threaded.

AJAX is not multi-threaded. It uses the same threading model as non AJAX websites. The page request (ajax or non ajax) may cause multiple threads to be used on the server but it is still one thread on the client (browser uses a single thread).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我为君王 2024-07-20 20:55:14

简而言之,是的。 在 ASP.NET 中,请求/响应通常在单个线程中处理...“请求”和“响应”之间没有明显的区别,它只是 ISAPI 将请求信息传递给 ASP.NET 处理程序,然后它将执行适当的代码并编写输出。 (尽管有一种机制可以在 ASP.NET 处于负载状态并需要有效利用可用线程时将请求从一个线程迁移到另一个线程。但我不能 100% 详细地确定何时或为何会发生这种情况。 )

浏览器端 JavaScript 和 AJAX 不是多线程的,但对某些人来说可能是多线程的,因为 AJAX 调用是异步的,而响应是事件驱动的; 也就是说,一旦请求被分派到服务器,JavaScript 线程就不会被阻塞。 可以自由地向服务器发送更多请求,并且响应可能会也可能不会按照发送的顺序返回。 然而,因为核心实际上只有一个线程,如果两个响应同时返回,一个响应将阻止另一个响应的执行,直到它完成。

In short, yes. In ASP.NET the request/response are normally handled in a single thread... there is no clear distinction between "request" and "response", it's simply ISAPI passing the request info to the ASP.NET handler and it will execute the appropriate code and write an output. (Although there is a mechanism for migrating a request from one thread to another when ASP.NET is under load and needs to make efficient use of available threads. But I am not 100% sure at a detailed level on when or why this happens.)

Browser-side JavaScript and AJAX are not multi-threaded, but it can appear that way to some because AJAX calls are asynchronous and the responses are event-driven; that is, once the request is dispatched to the server, the JavaScript thread is not blocked. It is free to send more requests to the server, and the responses may or may not come back in the same order they were sent. However, because at the core there really is only one thread, if two responses come back at the same time, one will block execution of the other until it is finished.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文