471,605 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

Dialog Threading error

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;

}

Jan 17 '06 #1
2 1532
And did you "Ensure that your Main function has STAThreadAttribute ..." ?

Willy.

"MAF" <mf*****@henwoodenergy.com> wrote in message
news:Ov**************@TK2MSFTNGP15.phx.gbl...
|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;
|
| }
|
|
|
Jan 17 '06 #2


Thank you that fixed the problem

*** Sent via Developersdex http://www.developersdex.com ***
Jan 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Vjay77 | last post: by
3 posts views Thread by AboutJAV | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.