ThreadStateException
-
Hi I have a main form which opens a thread that opens a new form. in the new form i'm trying to open an OpenFileDialog. when i'm trying: "if (projectFormOpenFileDialog.ShowDialog() == DialogResult.OK)" when running at debug mode i'm getting: "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process..." i have declared [STAThread] in the mainform function that opens the new form, also on the event that invokes the openfiledialog function. help on this will be most appreciated thanks, Yohay
-
Hi I have a main form which opens a thread that opens a new form. in the new form i'm trying to open an OpenFileDialog. when i'm trying: "if (projectFormOpenFileDialog.ShowDialog() == DialogResult.OK)" when running at debug mode i'm getting: "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process..." i have declared [STAThread] in the mainform function that opens the new form, also on the event that invokes the openfiledialog function. help on this will be most appreciated thanks, Yohay
OpenFileDialog cannot be shown from any thread other than your main GUI thread. You cannot open it from a background thread. You'll need to change your program accordingly (and by the way, you shouldn't be showing other forms from background threads, either).
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein
-
OpenFileDialog cannot be shown from any thread other than your main GUI thread. You cannot open it from a background thread. You'll need to change your program accordingly (and by the way, you shouldn't be showing other forms from background threads, either).
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein