Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Current thread must be set to single thread apartment (STA) mode before OLE

$
0
0
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;  
}

Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>