It has been a while since I’ve blogged, and I still haven’t delivered on my promise that I would explain how to control the AppDomain into which an add-in will be loaded. I’m not going to deliver on that promise today, either; mostly because I think that before I can dig into some of the more advanced performance and partial-trust scenarios supported by the AddInManager, we need to talk about how to shut down add-ins that are already running.
Once the add-in is loaded, all that needs to be done is to call AddIn.Unload specifying an appropriate timeout value. Calling this method notifies the add-in that it needs to do any cleanup, and then tears down the add-ins domain.
This brings us to another one of the classes in the
Another interesting point about unloading is that it isn’t guaranteed to terminate. What if the user’s code contains an infinite loop in their OnShutdown handler? Avoiding this and other potential pitfalls caused by bugs in end-user’s code has become an entire discipline itself, so I won’t go into it here. Suffice to say there is an easy way that you can avoid the 80% case of an add-in failing to shut down: pass a timeout value to Unload. By doing so, the