title: f#: windows form in a compiled program
body: <p>To visualize data from F# interactive console, I can do the following:</p>
  
  <pre><code>open System.Windows.Forms
  let  testgrid (x) =    
            let form = new Form(Visible = true)    
            let data = new DataGridView(Dock = DockStyle.Fill)    
            form.Controls.Add(data)    
            data.DataSource &lt;- x
  
  testgrid [|(1,1);(2,2)|]
  </code></pre>
  
  <p>But if  put the above in a compiled F# program and call <code>testgrid [|(1,1);(2,2)|]
  </code> within the program, I only got a freezing window without data. what need to be done to make this <code>testgrid</code> works for complied F# program?
  <strong>EDIT:</strong> with ildjarn's answer and some search, is the following code ok? Any pitfalls? </p>
  
  <pre><code>let testgrid x =
      let makeForm() = 
          use form = new Form()
          new DataGridView(Dock = DockStyle.Fill, DataSource = x) |&gt; form.Controls.Add
          Application.Run form
      let thread = new System.Threading.Thread(makeForm)
      thread.SetApartmentState(Threading.ApartmentState.STA)
      thread.Start()
  </code></pre>