asp.net - 在没有特定需要的情况下在 ASP.Net 页面上使用 Async ="true"可能出现的问题

标签 asp.net asynchronous webforms smtpclient sendasync

例如,我在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/

相关文章:

asp.net - 从 URL 中删除尾部斜杠

带有类的javascript表单验证

html - Bootstrap 导航栏切换按钮在某些页面上不起作用

javascript - 在 VS Code "Debug Console"中,运行 JavaScript 等待函数

c# - 使用数据集作为 Repeater 控件的数据源?

python - 无法在类内发送 websockets 消息

python 在后台触发并忘记异步函数

asp.net - 如何制作<asp :Menu and <asp:DropDownList on one line?

asp.net - 如何在两个网站中访问同一个Session?

javascript - jQuery 无法使用 jquery.cookie 插件读取 cookie