Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

.net - Long-running code within asp.net process

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...