Note that there are some explanatory texts on larger screens.

plurals
  1. POException when using FolderBrowserDialog
    primarykey
    data
    text
    <p>I'm getting the following Exception when trying to use FolderBrowserDialog: <code>System.Threading.ThreadStateException: 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.</code></p> <p>I have Googled this problem extensively and the solutions that everybody suggests seem to be to put <code>[STAThreadAttribute]</code> above the Main method, to delete all dll's from the Debug folder, or to use the <code>Invoke</code> method. I have tried all of these, and I still get the same exception.</p> <p>Here's the code:</p> <pre><code>public partial class Form1 : Form { public event EventHandler ChooseLocationHandler = null; public string DestFolder { set { textBox1.Text = value; } get { return textBox1.Text; } } public Form1() { InitializeComponent(); } private void ChooseLocationButton_Click(object sender, EventArgs e) { if (ChooseLocationHandler != null) ChooseLocationHandler(this, e); } } </code></pre> <p>And in my presenter is the following:</p> <pre><code>public partial class Presenter { Form1 myForm; public Presenter() { myForm = new Form1(); myForm.ChooseLocationHandler += ChooseLocationHandler; myForm.Show(); } public void ChooseLocationHandler(object obj, EventArgs e) { Form1 sender = (Form1)obj; FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.RootFolder = System.Environment.SpecialFolder.MyComputer; fbd.ShowNewFolderButton = true; if (fbd.ShowDialog() == DialogResult.Cancel) return; sender.DestFolder = fbd.SelectedPath; } } </code></pre> <p>I'm getting the Exception on fbd.ShowDialog().</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload