开发者

Can asp.net shut down an application-created thread?

The thread will be started on each Application_Start event.

It will be a monitoring thread which is supposed to run constantly.

So even if the app shuts down, once it is restarted the thread will start too ensuring 开发者_如何学Cit runs all the time.

However I need to be sure that this thread will not be stopped / shut down while the application is running.

So in a few words, does anybody know if asp.net could shut down such a thread without actualy stopping / recycling the application.


As a matter of design, you shouldn't depend on asp.net to run threads like this. Little things like app recycling can cause you a lot of trouble.

Instead, create a windows service to execute the thread. This way you don't have to worry about it.

Update
I just wanted to add a little more information.

IIS has the ability to execute your app across multiple threads and processes. A standard site installation usually only has a single process (aka: web garden) assigned which spins up around 20 threads to handle request processing.

However, any IIS administrator can easily add more processes to the mix. They usually do this when a site can hose a single process either because request processing takes too long, or the number of handler threads isn't enough, or as a temporary measure if the app has enough problems that a single thread will hose the entire process fairly often.

If you have a thread being spun on app start, then it will create one for each worker process the site has. This may be unexpected behavior to you or your successors.

Also, monitoring apps are almost always completely separate to the application they are monitoring. One of the primary reasons is that in the event the monitored process dies, hangs, or otherwise becomes unresponsive then the monitoring app itself still needs to carry on and log this information. Otherwise the monitored process could very well hose the monitoring app itself.

So, do yourself a favor and move this to its own process. The best way to do this on an IIS server is to create a windows service and give it the appropriate execution rights to do what you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜