E.g. we this code in the asp.net form codebihind:
private void btnSendEmails_OnClick()
{
Send100000EmailsAndWaitForReplies();
}
This code execution will be killed by the timeout reason. For resolving the problem I'd like to see something like this:
private void btnSendEmails_OnClick()
{
var taskId = AsyncTask.Run( () => Send100000EmailsAndWaitForReplies() );
// Store taskId for future task execution status checking.
}
And this method will be executed for some way outside the w3wp.exe process within a special enveronment.
Does anybody know a framework/toolset for resolving this kind of issues?
Update: The emails sending method is only an example of what I mean. In fact, I could have a lot of functionality need to be executed outside the asp.net working process.
E.g. this point is very important for an application which aggregates data from a couple of 3rd party services, do something with it and send it back to another service.
This has been discussed as a part of other questions:
Multithreading in asp.net
BackgroundWorker thread in ASP.NET
There is no good way to do this. You don't want any long running processes in the ASP.NET worker process, since it might recycle before you are done.
Write a Windows Service to run in the background that does the work for you. Drop messages into MSMQ to initiate tasks. Then they can run as long as they want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With