Prevent uninstall in setup project with OnBeforeUninstall

两盒软妹~` 提交于 2019-12-07 14:06:14

问题


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?


回答1:


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.");
}



回答2:


Make sure that in the setup project you chose the custom action for uninstalling, that s probably your case.



来源:https://stackoverflow.com/questions/4296176/prevent-uninstall-in-setup-project-with-onbeforeuninstall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!