Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Problem with File Open Dialog

Problem with File Open Dialog

Scheduled Pinned Locked Moved Managed C++/CLI
debugginghelpcomquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bubuzzz
    wrote on last edited by
    #1

    i am trying to write a small window form application. I use a file dialog to select a file in my computer. However, in the debug mode, when pressing the browse button, i got this error message : "An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll Additional information: 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." This problem happen only when i try to create a object of a class in the Form1.h file. If i delete the code of creating object, everything goes fine. I have checked the main function, it already had [STAThreadAttribute] marked on it. So, can you give me any suggestion, please? thanks

    A 1 Reply Last reply
    0
    • B bubuzzz

      i am trying to write a small window form application. I use a file dialog to select a file in my computer. However, in the debug mode, when pressing the browse button, i got this error message : "An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll Additional information: 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." This problem happen only when i try to create a object of a class in the Form1.h file. If i delete the code of creating object, everything goes fine. I have checked the main function, it already had [STAThreadAttribute] marked on it. So, can you give me any suggestion, please? thanks

      A Offline
      A Offline
      AVTProgrammerKeith
      wrote on last edited by
      #2

      You must set the Apartment state of the thread, to be STA ( Single Threaded Apartment ) to work with OLE. // Run application Thread Thread _threadAppProcessor = new Thread(new ThreadStart(StartThread)); _threadAppProcessor.SetApartmentState(ApartmentState.STA); _threadAppProcessor.Start();

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups