The easiest way to get AppDomain to shut down is to stop the parent process. In ASP.NET, you can do this by processing or stopping the application pool in which your code runs. We have code that does this to make sure the log is running and how I tested it in the past.
As for the complete failure, I'm not quite sure how you can do this ... There are exceptions in the hosting environment, so this can be impossible. Can you try Environment.Exit
or Environment.FailFast
, which will make the parent process exit immediately?
Edit: I forgot the easiest option here ... Just save Web.config - this will call the AppDomain utility!
Some alternatives ...
If you are using IIS, you can reuse the application pool that launches IIS Manager and follow these steps ...
- Find your application under "Sites". It could be under one of the sites there - perhaps like a virtual directory.
- Right-click the application and select "Application Management", then "Advanced Settings".
- Record the Application Pool.
- Locate the application pool under "application pools".
- Right-click on it and click on recycle.
For IIS Express, you can simply right-click the icon in the tray and in the user interface, which you can stop there.
For Visual Studio Development Server (Cassini), you can also use the tray to stop the application.
source share