Dialog Threading error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MAF

    #1

    Dialog Threading error

    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 STAThreadAttrib ute
    marked on it. This exception is only raised if a debugger is attached to the
    process.

    Here is the code

    this.openFileDi alog1.FileName = this.txtCompile Path.Text;

    DialogResult result = openFileDialog1 .ShowDialog(thi s);

    if (openFileDialog 1.ShowDialog() == DialogResult.OK )

    {

    this.txtCompile Path.Text = openFileDialog1 .FileName;

    }



  • Willy Denoyette [MVP]

    #2
    Re: Dialog Threading error

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

    Willy.

    "MAF" <mfraser@henwoo denergy.com> wrote in message
    news:Ov9tLq7GGH A.3896@TK2MSFTN GP15.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 STAThreadAttrib ute
    | marked on it. This exception is only raised if a debugger is attached to
    the
    | process.
    |
    | Here is the code
    |
    | this.openFileDi alog1.FileName = this.txtCompile Path.Text;
    |
    | DialogResult result = openFileDialog1 .ShowDialog(thi s);
    |
    | if (openFileDialog 1.ShowDialog() == DialogResult.OK )
    |
    | {
    |
    | this.txtCompile Path.Text = openFileDialog1 .FileName;
    |
    | }
    |
    |
    |


    Comment

    • Fraser Michael

      #3
      Re: Dialog Threading error



      Thank you that fixed the problem

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      Working...