使用 OnBeforeUninstall 防止安装项目中的卸载

发布于 2024-10-05 00:14:26 字数 399 浏览 7 评论 0原文

我重写了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终陌 2024-10-12 00:14:26

确保在安装项目中您选择了自定义卸载操作,这可能就是您的情况。

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

傲鸠 2024-10-12 00:14:26

在调用自定义代码之前,请调用 base.OnBeforeUninstall(savedState),以便注册的委托接收该事件,从而允许您的自定义代码在卸载之前执行。

protected override void OnBeforeUninstall(IDictionary savedState)
{
    // Add this
    base.OnBeforeUninstall(savedState);

    if (ApplicationIsBusy())
        throw new ApplicationException("Prevent uninstall while application busy.");
}

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.");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文