C# – safely spawn threads in ASP.NET MVC


I have a scheduled task that I need to kick off by browsing to a page, my webhost doesn't allow me to use the windows scheduler.

One job this task performs is to get some data from a bunch of other websites, due to how slow web-requests can be I've set up the task to use threading.

Running this task from an mvc action seems to cause the whole webserver to go wacky, making it refuse to load any more pages.

Is it bad to use threading from a web-app? Is there a way for me to safely do it? What threading limits are there? I really just need to know some more information?


If I use threads from the threadpool (which is used by the ASP.NET runtime (thanks Anton), can I limit how many of the threads it can use? What is the ASP.NET threadpool size limit?

Would be be better to have a separate site which does this? Perhaps a virtual folder containing a separate ASP.NET application? That would stop me from limiting the threadpool right?

Best Solution

When servicing incoming requests, ASP.NET runtime acquires threads from .NET ThreadPool, which has limited capacity. So if you're using threads from that tread pool, this may harm your applications' scalability.

The way around this will be spawning a usual Thread, but these can be killed when your AppPool gets recycled.