开发者

custom windows form on uninstall

开发者 https://www.devze.com 2023-03-01 09:01 出处:网络
I want to show my custom windows form on uninstall. I am going to use a C# custom action for this. How do I make the custom action wait till the user clicks OK 开发者_开发技巧or Cancel? I want my cust

I want to show my custom windows form on uninstall. I am going to use a C# custom action for this. How do I make the custom action wait till the user clicks OK 开发者_开发技巧or Cancel? I want my custom action to complete only when the form is closed. So do the following in my custom action:

    CollectUninstallData f = new CollectUninstallData();
            f.Show();
            return f.FormResult;

But the form blinks for a moment and the uninstall continues without waiting for the form to close. And this is logical since the GUI is in another thread. But how do I make it wait for the form to close?

I am aware that showing custom windows forms in install packages isn't cool, so if anyone can offer a more elegant solution, then I will thankfully accept it.


You have to use ShowDialog() method instead of Show(). The latter makes the form visible and returns control that's why your Custom Action stops its execution. The former shows the form as a modal dialog box and does not return until the user closes the form in any way.

CollectUninstallData f = new CollectUninstallData();
DialogResult r = f.ShowDialog();
f.Dispose(); 
return r;

If you want to know whether user clicked OK or Cancel, use this statement return r == DialogResult.OK ? 0 : 1. Return code of zero usually indicates success and non-zero is for failure.

0

精彩评论

暂无评论...
验证码 换一张
取 消