4

For example, I have some exception processing code in Global.asax, where I call the SendAsync() method of SmtpClient to notify myself about the error.

If the Async property of the certain page is "false", I receive no letter. So, to fix it, do I have to set Async="true" on EVERY page of my ASP.NET WebForms application? Can I get any problems here?

Async="true" is needed only for email sending in my application.

I will be grateful for any help...

1 Answers1

0

Please see full post at; 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.

Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158