Petrus Theron
Petrus Theron

Reputation: 28807

Prevent uninstall in setup project with 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?

Upvotes: 3

Views: 3430

Answers (2)

Subbu
Subbu

Reputation: 839

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

Upvotes: 2

Serdna
Serdna

Reputation: 31

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

Upvotes: 3

Related Questions