I have a perfectly working application, except in ONE computer. In this computer the application crashes when a SaveFileDialog opens. No errors, no exceptions.
After some research I found that one way to fix this crash is to make this SaveFileDialog in a new thread.
static void open(object name)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Microsoft Word Document (.docx)|*.docx";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.Title = "Where to save the " + (string)name + " ? ";
try
{
th.IsBackground = false;
boule = saveFileDialog1.ShowDialog() == DialogResult.OK;
ptth = saveFileDialog1.FileName;
}
catch (Exception exc)
{ MessageBox.Show(exc.Message); }
}
I put this in the Event:
Thread th = new Thread(new ParameterizedThreadStart(open));
th.Start("Quotation");
The problem is that I have an error
Current thread must be set to single thread apartment (STA) mode before OLE...
So I checked and I do have the "[STAThread]" before my Main. So I added this line in the "open" method:
th.SetApartmentState(ApartmentState.STA);
But a new error appear :
Failed to set the specified COM apartment state
What did I do wrong ? How to make a proper UI thread ? Is there an easier way?
EDIT : It's even more weird because in the app I use an OpenFileDialog to get a picture and it works perfectly. Is it an issue only for SaveFileDialog? Does it come from something else?