Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:39:40+00:00 2026-06-01T03:39:40+00:00

OpenFileDialog^ dialog = gcnew OpenFileDialog; dialog->ShowDialog(); What could possibly be wrong with this? I’m

  • 0
OpenFileDialog^ dialog = gcnew OpenFileDialog;
dialog->ShowDialog();

What could possibly be wrong with this?
I’m using Visual Studio 2008 Professional on Windows 7 with .NET Framework 3.5
I created a button and added a Click Function and I put the above code, and just throw this error:

An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll

I translated it from Portuguese to English since my Visual Studio threw the error in portuguese.

Additional information: The current thread should be defined in STA
Mode (Single Thread Apartment ) before OLE calls can be done. Check if
the Main Function has STAThreadAttribute checked. The Exception will
only be generated if the debugger is attached to the thread (or maybe
process).

and this is the original error in Portuguese Language:

Additional information: O thread atual deve ser definido no modo STA
(single thread apartment) antes que chamadas OLE possam ser feitas.
Verifique se a função Main tem STAThreadAttribute marcado. A exceção
somente será gerada se um depurador estiver anexado ao processo.

By the way, all microsoft default stuff is set, all libraries that Windows Forms Application preset when creating a project,
I hope I was clear enough
Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:39:42+00:00Added an answer on June 1, 2026 at 3:39 am

    It’s asking for you to put:

    [STAThread]

    on your main function. This means that clr should start a Single Threaded Apartment. Windows Forms wont work in a MTA (Multithreaded Apartment).

    Further reading here: http://blogs.msdn.com/b/jfoscoding/archive/2005/04/07/406341.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an OpenFileDialog in my Windows Form. I would like this dialog to
I have a WPF application which calls OpenFileDialog.ShowDialog. While this dialog is open it
I am using the following method to browse for a file: OpenFileDialog.ShowDialog() PictureNameTextEdit.Text =
I'm on Vista and I'm using Microsoft.Win32.OpenFileDialog class. When I call ShowDialog() I get
Is there a way to use visual studio's add assembly reference dialog (or something
When executing the following code: OpenFileDialog dialog = new OpenFileDialog(); DialogResult result = dialog.ShowDialog();
I'm using the OpenFileDialog class so a user can select an image file. I'd
var fileOpen = new OpenFileDialog(); var clickedOk = fileOpen.ShowDialog(); if (!((bool) clickedOk)) return; var
If I specify OpenFileDialog.AutoUpgradeEnabled = true, my program still shows the old XP-style dialog.
I have a customized OpenFileDialog (VS2008, C#, Windows Forms) with a ComboBox. The ComboBox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.