A has an ASP.NET 2.0 web application that should allow you to send emails. I have a windows service that sends emails immediately. My web application composes an email message according to some template and puts it in MSMQ, and the service receives it from there.
The problem is that composing a message from a template may take some time, and I do not want the user to wait for the message to be compiled and submitted to the service.
I am thinking of some kind of background process that will listen on the internal queue of notification requests. If the queue is empty, the process does nothing, but as soon as the message appears, it starts processing the message. I want to have only one process, so as not to create many threads.
My current idea is to write a task scheduler that will contain a queue of notification requests. When a new item is added to the queue, the scheduler checks to see if the notification process is running. If so, just add the request to the queue. Otherwise, it creates a new thread that will read the queue until it becomes empty and executes notification requests.
My concern is that I must be sure that my thread will not die after ASP.NET completes the response to the client, because it is the parent thread for my thread. And the question is, what is the best way to do this (or can it be done)?
PS It's normal that my thread dies if IIS processes the ASP.NET process due to user inactivity.
source
share