Curious about long-running background tasks an AppDomain shutdown

Topics: Core, General, Troubleshooting
Mar 30, 2012 at 10:51 PM
Edited Mar 30, 2012 at 10:58 PM

I was wondering about that after coming across an old post by Phil Haack:

Currently, the AppDomain doesn't know about the background tasks, so there is a risk they may get interrupted if AppDomain gets torn down. For long running tasks this might be a problem and corrupt the data being processed (if eg. the interruption would happen in the middle of some operation).

That looks like an issue. Correct me please if I'm wrong.

Apr 1, 2012 at 2:22 AM

Transactions should take care of data corruptions.

Apr 5, 2012 at 5:32 AM

Not quite - what about long tasks that do not rely on database transactions, like eg. involving talking to web services, sending e-mails? Having a stop event would be good to have, to allow interrupting a task nicely, do some cleanup etc..

Apr 23, 2012 at 9:43 AM
Edited Apr 23, 2012 at 9:48 AM

Aren't finally blocks run when the AppDomain shuts down? That still wouldn't protect from e.g. powering off the server, but still...

Apr 23, 2012 at 1:49 PM

@Piedone Good point - yes the unexecuted finalizers are being executed on Thread.Abort. This may help to some degree.