例如,我在Global.asax中有一些异常处理代码,在那里我调用了SmtpClient的SendAsync()方法来通知自己错误。
如果某个页面的 Async 属性为“false”,则我不会收到任何信件。那么,要修复它,我是否必须在我的 ASP.NET WebForms 应用程序的每个页面上设置 Async="true"?我可以在这里遇到任何问题吗?
Async="true"仅用于在我的应用程序中发送电子邮件。
我将不胜感激任何帮助...
最佳答案
请参阅完整的帖子;
The Dangers of Implementing Recurring Background Tasks In ASP.NET
There are three main risks, one of which I’ll focus on in this blog post.
1- An unhandled exception in a thread not associated with a request will take down the process. This occurs even if you have a handler setup via the Application_Error method. I’ll try and explain why in a follow-up blog post, but this is easy to deal with.
2- If you run your site in a Web Farm, you could end up with multiple instances of your app that all attempt to run the same task at the same time. A little more challenging to deal with than the first item, but still not too hard. One typical approach is to use a resource common to all the servers, such as the database, as a synchronization mechanism to coordinate tasks.
3- The AppDomain your site runs in can go down for a number of reasons and take down your background task with it. This could corrupt data if it happens in the middle of your code execution.
关于asp.net - 在没有特定需要的情况下在 ASP.Net 页面上使用 Async ="true"可能出现的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16895562/