I read Phil Haack's article on using the IRegisteredObject
interface to be sure that a background thread finishes completion when the AppDomain is brought down, and I implemented it into my code. However, I'm not entirely sure how to simulate a AppDomain crash in order to test it. How can I simulate an AppDomain crash?
Easiest way to get an AppDomain to shutdown is by causing the parent process to stop. In ASP.NET you can do this by recycling or stopping the application pool that your code is running under. We have some code that does that to make sure logging gets flushed and that's how I've tested it in the past.
As for a complete crash, I'm not really sure how you could go about that... The hosting environment catches exceptions so it might not be doable. You could try Environment.Exit
or Environment.FailFast
which will force the parent process to exit immediately?
Edit: I forgot the easiest option here... Just save Web.config - this will trigger an AppDomain recycle!
Some alternates...
If you're running using IIS you can recycle the application pool starting IIS Manager and following these steps...
For IIS Express you can simply right-click the icon in the tray and in the UI you should be able to stop the application there.
For Visual Studio Development Server (Cassini) you can also use the tray to stop the application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With