在ASP.NET应用程序中使用线程。 [英] The use of threads in a ASP.NET app.

查看:75
本文介绍了在ASP.NET应用程序中使用线程。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个基本的负载均衡器(在我们的Web服务中)解决方案。这个负载均衡器的目的是使用服务器状态更新数组。

我们有几个服务器可以访问以便检索信息。


来自a ?? Application_Starta ?? (Global.asax),我创建了尽可能多的线程

作为我们可用的服务器。这个想法是每个线程将查询每个

服务器并更新公共数组中的标志。当一个?? ?? ??请求进来,

系统检查两件事:


*服务器可用性(在线与离线)

*服务器负载(基于每次线程

发送新查询时服务器返回的值)


我注意到线程可能会停止工作。有时它们运行时间很长

,有时它们会运行很短的时间。我开始阅读

一些与线程相关的帖子,我发现这个是一个?在asp.net中的线程

问题 - 线程stopa ??创建于2004年12月12日,其中一个??约翰桑德萨? (谁是回复的
)说在ASP.NET应用程序中使用线程是一个糟糕的想法。他说 - 不要在ASP.NET上使用线程.a ??


如果这是真的,我该如何处理这个负载均衡器项目?任何想法

将不胜感激。


提前致谢。

I am trying to write a basic load balancer (in our web service) solution. The
purpose of this load balancer is to keep an array updated with server status.
We have several servers that can be accessed in order to retrieve information.

From within the a??Application_Starta?? (Global.asax), I create as many threads
as servers we have available. The idea is that each thread will query each
server and update a flag in the public array. When a a??truea?? request comes in,
the system checks for two things:

* Server availability (on-line vs. off-line)
* Server load (based on a value returned by the server every time a thread
sends a new query)

I noticed that the threads may stop working. Sometimes they run for a long
time and sometimes they run for a short period of time. I started reading
some posts related to threading and I found this one a??Threading in asp.net
issue - Thread stopsa?? created on 11/12/2004 where a??John Saundersa?? (who is
responding) says that the use of threads in a ASP.NET application is a bad
idea. He said a??don''t use threads with ASP.NET.a??

If this is true, how can I approach this load balancer project? Any ideas
will be greatly appreciated.

Thanks in advance.

推荐答案

在asp.net中使用线程没有任何问题。 asp.net将实际上

对你创建的线程一无所知,它们只是标准的.net线程。

它们将在asp.net工作进程的安全上下文中运行。如果他们退出苛刻的话,那么他们可能就错了。如果你的线程中没有错误

日志记录特征,则需要添加它。


注意:允许asp.net在回收时卸载其appdomains事件,你

应该检查线程中止请求。


- 布鲁斯(sqlwork.com)

" mareal" ; < m@m.com>在消息中写道

news:70 ********************************** @ microsof t.com ...

|我正在尝试编写一个基本的负载均衡器(在我们的Web服务中)解决方案。



|此负载均衡器的目的是使用服务器更新数组

状态。

|我们有几个服务器可以访问,以便检索

信息。

|

|从Application_Start中开始。 (Global.asax),我创建尽可能多的

线程

|作为我们可用的服务器。这个想法是每个线程都会查询每个

|服务器并更新公共阵列中的标志。当真实时要求来

in,

|系统检查两件事:

|

| *服务器可用性(在线与离线)

| *服务器负载(基于每次线程

|发送新查询时服务器返回的值)

|

|我注意到线程可能会停止工作。有时它们会运行很长时间

|时间,有时他们会跑一小段时间。我开始阅读

|一些与线程相关的帖子,我发现这个在asp.net中的线程

|问题 - 线程停止创建于2004年12月12日,其中John Saunders (谁是

|响应)说在ASP.NET应用程序中使用线程很糟糕

|理念。他说不要在ASP.NET上使用线程。

|

|如果是这样,我该如何处理这个负载均衡器项目?任何想法

|非常感谢。

|

|提前致谢。

|
there is nothing wrong with using threads in asp.net. asp.net will actualy
know nothing of threads you create, they are just standard .net threads.
they will run under the security context of the asp.net worker process. if
they are exiting earky, they are probably erroring out. if you have no error
logging featue in your thread, you need to add it.

note: to allow asp.net to unload its appdomains on recycle events, you
should check for the thread abort request.

-- bruce (sqlwork.com)
"mareal" <m@m.com> wrote in message
news:70**********************************@microsof t.com...
| I am trying to write a basic load balancer (in our web service) solution.
The
| purpose of this load balancer is to keep an array updated with server
status.
| We have several servers that can be accessed in order to retrieve
information.
|
| From within the "Application_Start" (Global.asax), I create as many
threads
| as servers we have available. The idea is that each thread will query each
| server and update a flag in the public array. When a "true" request comes
in,
| the system checks for two things:
|
| * Server availability (on-line vs. off-line)
| * Server load (based on a value returned by the server every time a thread
| sends a new query)
|
| I noticed that the threads may stop working. Sometimes they run for a long
| time and sometimes they run for a short period of time. I started reading
| some posts related to threading and I found this one "Threading in asp.net
| issue - Thread stops" created on 11/12/2004 where "John Saunders" (who is
| responding) says that the use of threads in a ASP.NET application is a bad
| idea. He said "don''t use threads with ASP.NET."
|
| If this is true, how can I approach this load balancer project? Any ideas
| will be greatly appreciated.
|
| Thanks in advance.
|


>我注意到线程可能会停止工作。有时它们会运行一段很长的
> I noticed that the threads may stop working. Sometimes they run for a long
时间,有时它们会运行很短的时间。


这些线程是否会因你的应用程序停止而停止?

应用程序将在一段时间后停止,没有请求。这将停止

任何子线程。


-

HTH,


Kevin Spencer

Microsoft MVP

..Net开发人员

跟随者和贷款人都不是。


mareal < m@m.com>在消息中写道

news:70 ********************************** @ microsof t.com ...我正在尝试编写一个基本的负载均衡器(在我们的Web服务中)解决方案。
这个负载均衡器的目的是保持阵列更新服务器状态。
我们有几个服务器可以访问,以便检索
信息。

来自Application_Start。 (Global.asax),我创建了与我们可用的服务器一样多的
线程。这个想法是每个线程将查询每个服务器并更新公共数组中的标志。当真实时请求来
,系统检查两件事:

*服务器可用性(在线与离线)
*服务器负载(基于每次线程发送新查询时服务器返回的值。

我注意到线程可能会停止工作。有时他们会跑很长一段时间,有时他们会跑很短的时间。我开始阅读
一些与线程相关的帖子,我发现这个在asp.net中线程攻击
问题 - 线程停止创建于2004年12月12日,其中John Saunders (谁回复)说在ASP.NET应用程序中使用线程是一个糟糕的想法。他说不要在ASP.NET上使用线程。

如果这是真的,我该如何处理这个负载均衡器项目?任何想法将非常感谢。

提前致谢。
time and sometimes they run for a short period of time.
Would these threads stopping by any chance coincide with your app stopping?
The app will stop after a period of time with no requests. That would stop
any child threads.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"mareal" <m@m.com> wrote in message
news:70**********************************@microsof t.com...I am trying to write a basic load balancer (in our web service) solution.
The
purpose of this load balancer is to keep an array updated with server
status.
We have several servers that can be accessed in order to retrieve
information.

From within the "Application_Start" (Global.asax), I create as many
threads
as servers we have available. The idea is that each thread will query each
server and update a flag in the public array. When a "true" request comes
in,
the system checks for two things:

* Server availability (on-line vs. off-line)
* Server load (based on a value returned by the server every time a thread
sends a new query)

I noticed that the threads may stop working. Sometimes they run for a long
time and sometimes they run for a short period of time. I started reading
some posts related to threading and I found this one "Threading in asp.net
issue - Thread stops" created on 11/12/2004 where "John Saunders" (who is
responding) says that the use of threads in a ASP.NET application is a bad
idea. He said "don''t use threads with ASP.NET."

If this is true, how can I approach this load balancer project? Any ideas
will be greatly appreciated.

Thanks in advance.



谢谢布鲁斯。没有回答你的问题,不,我还没有任何记录。我打算这样做。
正计划这样做。你刚才提到了我想问的问题。你说b $ b说我创建的线程是标准的.NET线程,并且它们在aspnet_wp进程的安全上下文中运行

。我希望能够监控我创建的线程
。只需检查IsAlive属性就足够了吗?


您能否通过卸载它的

appdomains来解释一下你的意思?


" bruce barker"写道:
Thank you Bruce. Unswering your question, no, I dona??t have any logging yet. I
was planning on doing this. You just mentioned something I wanted to ask. You
say that the threads I create are standard .NET threads and that they run
under the security context of the aspnet_wp process. I would like to be able
to monitor the threads I create. Is it enough to just check IsAlive property?

Could you please explain a bit more what you mean by unloading its
appdomains?

"bruce barker" wrote:
在asp.net中使用线程没有任何问题。 asp.net将实际上不知道你创建的线程,它们只是标准的.net线程。
它们将在asp.net工作进程的安全上下文中运行。如果他们退出诡异,他们可能会出错。如果您的线程中没有错误
日志记录特征,则需要添加它。

注意:要允许asp.net在回收事件中卸载其appdomains,您应该
检查线程中止请求。

- bruce(sqlwork.com)

" mareal" < m@m.com>在消息中写道
新闻:70 ********************************** @ microsof t.com。 ..
|我正在尝试编写一个基本的负载均衡器(在我们的Web服务中)解决方案。

|此负载均衡器的目的是使阵列更新为服务器状态。
|我们有几个服务器可以访问,以便检索
信息。
|
|从Application_Start中开始。 (Global.asax),我创建了尽可能多的
线程作为我们可用的服务器。这个想法是每个线程都会查询每个
|服务器并更新公共阵列中的标志。当真实时请求来

|系统检查两件事:
|
| *服务器可用性(在线与离线)
| *服务器负载(基于每次线程
|发送新查询时服务器返回的值)
|
|我注意到线程可能会停止工作。有时它们运行了很长时间
|时间,有时他们会跑一小段时间。我开始阅读
|一些与线程相关的帖子,我发现了这个在asp.net中的线程问题 - 线程停止创建于2004年12月12日,其中John Saunders (谁是
|响应)说在ASP.NET应用程序中使用线程是不好的理念。他说不要在ASP.NET上使用线程。
|
|如果是这样,我该如何处理这个负载均衡器项目?任何想法
|将不胜感激。
|
|提前致谢。
|
there is nothing wrong with using threads in asp.net. asp.net will actualy
know nothing of threads you create, they are just standard .net threads.
they will run under the security context of the asp.net worker process. if
they are exiting earky, they are probably erroring out. if you have no error
logging featue in your thread, you need to add it.

note: to allow asp.net to unload its appdomains on recycle events, you
should check for the thread abort request.

-- bruce (sqlwork.com)
"mareal" <m@m.com> wrote in message
news:70**********************************@microsof t.com...
| I am trying to write a basic load balancer (in our web service) solution.
The
| purpose of this load balancer is to keep an array updated with server
status.
| We have several servers that can be accessed in order to retrieve
information.
|
| From within the "Application_Start" (Global.asax), I create as many
threads
| as servers we have available. The idea is that each thread will query each
| server and update a flag in the public array. When a "true" request comes
in,
| the system checks for two things:
|
| * Server availability (on-line vs. off-line)
| * Server load (based on a value returned by the server every time a thread
| sends a new query)
|
| I noticed that the threads may stop working. Sometimes they run for a long
| time and sometimes they run for a short period of time. I started reading
| some posts related to threading and I found this one "Threading in asp.net
| issue - Thread stops" created on 11/12/2004 where "John Saunders" (who is
| responding) says that the use of threads in a ASP.NET application is a bad
| idea. He said "don''t use threads with ASP.NET."
|
| If this is true, how can I approach this load balancer project? Any ideas
| will be greatly appreciated.
|
| Thanks in advance.
|



这篇关于在ASP.NET应用程序中使用线程。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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