Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
289 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...