Prevent uninstall in setup project with OnBeforeUninstall
I overrode OnBeforeUninstall
to stop my application's setup project from uninstalling it under certain circumstances, but it seems like it is just not being called and has no effect.
protected override开发者_开发知识库 void OnBeforeUninstall(IDictionary savedState)
{
if (ApplicationIsBusy())
throw new ApplicationException("Prevent uninstall while application busy.");
}
I am able to cancel uninstall by overriding the Uninstall
method, but by then the setup project has already closed my application. How do I "fail" an uninstall attempt when my application is busy before the setup project tries to close it when it is running and interrupts my worker process?
Make sure that in the setup project you chose the custom action for uninstalling, that s probably your case.
Before calling your custom code, call the base.OnBeforeUninstall(savedState) so that registered delegates receive the event thereby allowing your custom code to execute before the uninstall.
protected override void OnBeforeUninstall(IDictionary savedState)
{
// Add this
base.OnBeforeUninstall(savedState);
if (ApplicationIsBusy())
throw new ApplicationException("Prevent uninstall while application busy.");
}
精彩评论