C# 使用OnBeforeUninstall阻止安装项目中的卸载
在某些情况下,我在卸载前重写了C# 使用OnBeforeUninstall阻止安装项目中的卸载,c#,setup-project,uninstallation,C#,Setup Project,Uninstallation,在某些情况下,我在卸载前重写了onbeforeunstall,以阻止应用程序的安装项目卸载它,但它似乎只是没有被调用,并且没有任何效果 protected override void OnBeforeUninstall(IDictionary savedState) { if (ApplicationIsBusy()) throw new ApplicationException("Prevent uninstall while application busy.");
onbeforeunstall
,以阻止应用程序的安装项目卸载它,但它似乎只是没有被调用,并且没有任何效果
protected override void OnBeforeUninstall(IDictionary savedState)
{
if (ApplicationIsBusy())
throw new ApplicationException("Prevent uninstall while application busy.");
}
我可以通过覆盖
uninstall
方法取消卸载,但此时安装项目已经关闭了我的应用程序。在安装项目试图关闭正在运行的应用程序并中断工作进程之前,如果我的应用程序正忙,我如何“失败”卸载尝试?在调用自定义代码之前,请调用base.onbeforeunstall(savedState)这样,已注册的代理将接收事件,从而允许在卸载之前执行自定义代码
protected override void OnBeforeUninstall(IDictionary savedState)
{
// Add this
base.OnBeforeUninstall(savedState);
if (ApplicationIsBusy())
throw new ApplicationException("Prevent uninstall while application busy.");
}
请确保在安装项目中选择了要卸载的自定义操作,这可能是您的情况。尝试在其中写入跟踪消息:仅检查是否调用了该方法。您也可以使用MSDN中的debugView检查跟踪消息:“在派生类中重写OnBeforeUninstall时,请确保调用基类的OnBeforeUninstall方法,以便注册的委托接收事件。”