gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:00:21 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com