Dialog Threading error

M

MAF

I recently updated a simple program that uses a filedialog control to locate
a file. When I try and run the following code I get this error:

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.

Here is the code

this.openFileDialog1.FileName = this.txtCompilePath.Text;

DialogResult result = openFileDialog1.ShowDialog(this);

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

this.txtCompilePath.Text = openFileDialog1.FileName;

}
 
W

Willy Denoyette [MVP]

And did you "Ensure that your Main function has STAThreadAttribute ..." ?

Willy.

|I recently updated a simple program that uses a filedialog control to
locate
| a file. When I try and run the following code I get this error:
|
| 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.
|
| Here is the code
|
| this.openFileDialog1.FileName = this.txtCompilePath.Text;
|
| DialogResult result = openFileDialog1.ShowDialog(this);
|
| if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
| {
|
| this.txtCompilePath.Text = openFileDialog1.FileName;
|
| }
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top