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. Windows Forms
  4. ThreadStateException

ThreadStateException

Scheduled Pinned Locked Moved Windows Forms
debuggingcomhelp
3 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.
  • J Offline
    J Offline
    johland
    wrote on last edited by
    #1

    Hi I have a main form which opens a thread that opens a new form. in the new form i'm trying to open an OpenFileDialog. when i'm trying: "if (projectFormOpenFileDialog.ShowDialog() == DialogResult.OK)" when running at debug mode i'm getting: "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..." i have declared [STAThread] in the mainform function that opens the new form, also on the event that invokes the openfiledialog function. help on this will be most appreciated thanks, Yohay

    P 1 Reply Last reply
    0
    • J johland

      Hi I have a main form which opens a thread that opens a new form. in the new form i'm trying to open an OpenFileDialog. when i'm trying: "if (projectFormOpenFileDialog.ShowDialog() == DialogResult.OK)" when running at debug mode i'm getting: "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..." i have declared [STAThread] in the mainform function that opens the new form, also on the event that invokes the openfiledialog function. help on this will be most appreciated thanks, Yohay

      P Offline
      P Offline
      Patrick Etc
      wrote on last edited by
      #2

      OpenFileDialog cannot be shown from any thread other than your main GUI thread. You cannot open it from a background thread. You'll need to change your program accordingly (and by the way, you shouldn't be showing other forms from background threads, either).


      It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein

      J 1 Reply Last reply
      0
      • P Patrick Etc

        OpenFileDialog cannot be shown from any thread other than your main GUI thread. You cannot open it from a background thread. You'll need to change your program accordingly (and by the way, you shouldn't be showing other forms from background threads, either).


        It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein

        J Offline
        J Offline
        johland
        wrote on last edited by
        #3

        many thanks for your help. y

        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