The problem is that the MSI thread is running as an MTA thread, but the FileDialog.ShowDialog requires an STA thread. To achieve this you will need to start a STA background thread and call the dialog from that thread. Basically I did the following:
- Added the DialogState class. This keeps track of the input and output for the thread.
- Added the STAShowDialog function. This function takes a FileDialog, calls ShowDialog on a background STA thread, and then returns the results.
- Changed the call from DialogResult ret = frm.ShowDialog(); to DialogResult ret = STAShowDialog(frm);
Check this post for a complete information
http://blogs.msdn.com/b/smondal/archive/2012/12/31/10059279.aspx[
^].
[edit]Code lang changed[/edit]