When Asp.net terminates background threads?

前端 未结 3 1493
一向
一向 2021-01-27 10:42

I was working on a project and there is bulk e-mail sending part of it and when user clicks on the button, he/she gets the \"Thanks the e-mails have been sent\" immediately as a

3条回答
  •  [愿得一人]
    2021-01-27 11:31

    When you call QueueUserWorkItem a new thread will be drawn from the thread pool if available and execute the callback function on this thread. If no threads are available, the function will block until a thread is freed. Once it finishes the execution of the method the thread will be suspended and returned to the pool for further reuse. Your only concern should be the fact that threads from the pool are also used to service requests, so if you perform lengthy tasks on them you could jeopardize the whole system request servicing capabilities because there's a limited number of threads in the pool and if all of them are busy performing lengthy operations future HTTP requests will be queued. As an alternative you could consider creating threads manually: new Thread(state => { }).Start();

提交回复
热议问题