使用 OnBeforeUninstall 防止安装项目中的卸载
我重写了 OnBeforeUninstall 来阻止我的应用程序的安装项目在某些情况下卸载它,但它似乎只是没有被调用并且没有任何效果。
protected override void OnBeforeUninstall(IDictionary savedState)
{
if (ApplicationIsBusy())
throw new ApplicationException("Prevent uninstall while application busy.");
}
我可以通过重写 Uninstall
方法来取消卸载,但那时安装项目已经关闭了我的应用程序。当我的应用程序正忙于安装项目尝试在其运行时关闭它并中断我的工作进程之前,我如何“失败”卸载尝试?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保在安装项目中您选择了自定义卸载操作,这可能就是您的情况。
Make sure that in the setup project you chose the custom action for uninstalling, that s probably your case.
在调用自定义代码之前,请调用 base.OnBeforeUninstall(savedState),以便注册的委托接收该事件,从而允许您的自定义代码在卸载之前执行。
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.