1

I've been reading a lot about how IIS manages threads for http requests (taking them from the pool once needed and "releasing" once the request has been processed)...

And about the whole concept of async requests in, for example, ASP.NET MVC that are used to "release" threads back to the pool when long-wait I/O operations are executed on the side.

But what I can't understand is - if I start "normal" threads using Thread.Start() - these threads are "unpooled", right? And they don't use up the IIS request thread pool - is this correct?

I tried Googling but can't find the exact answer. I know that Thread.Start does not use the .NET's built-in ThreadPool at all - but I have doubts about IIS using the same mechanisms for its request threads, could it be that IIS "request pool" is different from the .NET's ThreadPool and uses some lower level pool, so that my Thread.Start will also end up there?

I guess what I'm asking is - is there a limit on Thread.Start() in an ASP.NET app and can a lot of Thread.Start's block my web application during a high load because of thread-queuing?

UPDATE: found this answer but it does not explain why and what happens: Why ASP.NET kills my background thread?

Community
  • 1
  • 1
jazzcat
  • 4,351
  • 5
  • 36
  • 37
  • Why are you calling Thread.Start in ASP.NET in the first place? – mason Apr 23 '17 at 23:20
  • For an async operation (email sending service) that needs to finish even after the IIS tries to abort the thread (IIS sometimes does that after the request has been aborted or ended). I found Thread.Start to be the only reliable way. – jazzcat Apr 23 '17 at 23:23
  • 1
    That's not a reliable or good way to do it. The best place to do this is a completely separate application. Run Hangfire in a separate Windows service, or implement a queue such as RabbitMQ and have a background service pick up jobs off the queue and process them. If this is a low importance app, you might get away with running Hangfire directly in the site, but don't use Thread.Start. Far too many pitfalls for that to be a good way of doing it. See Scott Hanselman's [blog on the subject](https://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx). – mason Apr 23 '17 at 23:25
  • @mason thanks for the Hangfire mention, wasn't aware of it, looks interesting. – jazzcat Apr 23 '17 at 23:45
  • @mason can you suggest a read about the "many pitfalls" of having `Thread.Start` in a web app? Sorry for using your time, but if must already have something on your mind – jazzcat Apr 23 '17 at 23:54
  • The link I provided in my previous comment contains plenty of information on that subject. – mason Apr 24 '17 at 00:04

0 Answers0