title: Opening files in a form, ThreadStateException was unhandled
body: <p>I have a form name <code>Form1.cs</code> and when I run it, it has an error: ThreadStateException was unhanded.</p>
  
  <p>I am trying to open a file from a desired location, then latter on have it so the file will load automatically in a text box on screen. I have heard of this <code>[STAThread]</code> but am confused on how to add it. When I try to use it in the main method it comes up as "not valid on this declaration type".</p>
  
  <p><code>Form1.cs</code>:</p>
  
  <pre><code>public partial class Form1 : Form
  {
  
      public Form1()
      {
          InitializeComponent();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          OpenFileDialog openFileDialog1 = new OpenFileDialog();
  
          if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
          {
              string strfilename = openFileDialog1.FileName;
  
              MessageBox.Show(strfilename);
          }
      }
  }
  </code></pre>
  
  <p>The Solution Explorer:</p>
  
  <p><img src="https://i.stack.imgur.com/ekLRA.png" alt="enter image description here"></p>
  
  <p><code>Game1.cs</code> is were it starts, I have a function witch calls on the form to pop up by pressing F1:</p>
  
  <pre><code>protected override void Update(GameTime gameTime)
      {
          // Allows the game to exit
          if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
              this.Exit();
  
          if (Keyboard.GetState().IsKeyDown(Keys.F1) &amp;&amp; (!isForm1Open))
          {
              isForm1Open = true;
              Form1 form1 = new Form1();
              form1.FormClosed += new System.Windows.Forms.FormClosedEventHandler(
                  (s, e) =&gt; { isForm1Open = false; });
              form1.ShowDialog();
          }
  
          base.Update(gameTime);
      }
  </code></pre>