title: How to run a winforms Form window concurrently within a script
body: <p>I am trying to run a System.windows.form object alongside with my main script.
  For example, I want to run a PowerShell script which has a loop and never stops. I wish to be able to terminate the execution using a button on a WPF Form object.</p>
  
  <p>I have tried the method form.show(), but it doesn't give me control.</p>
  
  <pre><code>clear host
  Function hey(){
      # code to exit, or do what I want it to do.
  }
  Add-Type -AssemblyName System.Windows.Forms
  
  $form = New-Object Windows.Forms.Form
  $form.Size = New-Object Drawing.Size @(1024,768)
  $form.StartPosition = "CenterScreen"
  $btn = New-Object System.Windows.Forms.Button 
  $btn.Location = New-Object System.Drawing.Point(15, 15)
  $btn.add_click({$(hey)})
  $btn.Text = "Click here"
  $form.Controls.Add($btn)
  
  
  while($true){
      write-host "int = $int."
      start-sleep 3
      $int = $int + 1
      $drc = $form.ShowDialog()
  }
  </code></pre>
  
  <p>Thank you very much in advance!</p>