防止安装项目卸载与OnBeforeUninstall [英] Prevent uninstall in setup project with OnBeforeUninstall
问题描述
我推翻 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?
推荐答案
在呼唤你的自定义代码,调用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.
protected override void OnBeforeUninstall(IDictionary savedState)
{
// Add this
base.OnBeforeUninstall(savedState);
if (ApplicationIsBusy())
throw new ApplicationException("Prevent uninstall while application busy.");
}
这篇关于防止安装项目卸载与OnBeforeUninstall的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!