Anees Deen
Anees Deen

Reputation: 1413

open file dialog not working from Installer class in c# application

I have designed my project MSi file through Visual Studio 2010 Setup and deployment project in which I added one custom action. In the custom action, I am opening OpenFile dialog . It is working fine from inside Application. But from Installer it hangs out.

public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
             OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = " Dialog";
             ....
             ....
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                tempPath = fdlg.SafeFileName;
                mappingPath = fdlg.FileName;
            }
    }

Upvotes: 1

Views: 1058

Answers (1)

Praveen
Praveen

Reputation: 56509

From Soumitra Mondal's WebLog

FileDialog.ShowDialog requires STA thread, whereas MSI is running as MTA thread. In Order to achieve this you will need to start a STA background thread and call the dialog from that thread.

You need to change the your call from

DialogResult ret = fdlg.ShowDialog(); to

DialogResult ret = STAShowDialog(fdlg);

Upvotes: 1

Related Questions