如何在 ASP.NET Web 应用程序中获取服务请求的线程?

发布于 2024-12-14 19:08:22 字数 220 浏览 0 评论 0原文

我们都知道,每当我们请求网页或点击按钮(在网页上)时,就会在服务器上创建一个新线程来为我们提供所需的结果。

现在,我需要的是服务此请求的线程。我需要将此服务线程的 Apartment 状态设置为 STA,以便使用 Watin API。

我正在做的是在服务器上打开一个新的 IE 浏览器窗口,我在按钮单击事件中编写了该窗口的代码。现在 Watin 要求公寓状态为 STa。

谢谢。

We all know that whenever we request for a web page or hit a button(on a web page) then a new thread is created on the server to give us the required result.

Now, what I need is the thread which is serving a this request. I need to set the Apartment state of this serving thread to STA, for working with Watin API.

What I am doing is I am opening a new IE browser window on the server, the code for that I have written inside the button click event. Now Watin requires the apartment state to be STa.

Thanks.

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

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

发布评论

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

评论(3

绿光 2024-12-21 19:08:22

实际上,并不是创建一个新线程来处理每个 Web 请求。该请求是在从可用线程共享池中获取的线程上处理的。从头开始创建一个新线程非常昂贵,有时比您想要在线程上执行的任务花费更长的时间。

您可以使用 System.Threading.Thread.CurrentThread 获取当前正在执行的线程。

由于您的请求在 IIS 服务器管理的共享线程上执行,因此更改线程的单元模型可能不是一个好主意。

Actually, a new thread is not created to handle every web request. The request is handled on a thread taken from a shared pool of available threads. Creating a new thread from scratch is pretty expensive, sometimes taking longer than the task you want to perform on the thread.

You can get the current executing thread using System.Threading.Thread.CurrentThread.

Since your request is executing on a shared thread managed by the IIS server, it's probably not a good idea to change the apartment model of the thread.

冷血 2024-12-21 19:08:22

您不需要了解有关服务器的任何信息,因为 WatiN 是客户端自动化。

请按照此处针对您的特定情况的说明进行操作:http://watin.org/documentation/sta-apartmentstate/< /a>

You shouldn't need to know anything about the server as WatiN is client-side automation.

Follow the directions here for your particular scenario: http://watin.org/documentation/sta-apartmentstate/

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