title: Is it possible to run 2 functions at the same time in PowerShell?
body: <p>In a PowerShell script I have</p>
  
  <pre><code>function f1{ do something}
  function f2{ do something else}
  button1
  button2
  richtextbox
  </code></pre>
  
  <p>When I press <code>button1</code> it runs <code>f1</code> and it outputs data in the <code>richtextbox</code>.
  When I press <code>button2</code> I need the script to run <code>f2</code> even if <code>f1</code> hasn't finished. The data from <code>f2</code> I don't need it to be outputted in the same <code>richtextbox</code>, it can be a different one.
  My question is: can 2 different functions run at the same time in PowerShell?</p>
  
  <p>Update:
  For my PowerShell script I've done a GUI that has a bunch of button that do different things.
  When I press one button it starts to connect to a serial device and outputs data to the richtextbox and at some points it saves data into a text file. 
  2 other buttons have the following functions: it takes parts of data from the text file saved, opens a temporary php web server, opens a link to create a pdf file, and the it send the file to the correct printer/tray for printing.
  These 2 buttons I've just noticed that they work.
  My problem is with the buttons that are in a popup form.
  One other button from my main form opens a popup form and populates it with data from the text file saved above.</p>
  
  <pre><code>$print_equip_button.Add_Click({
      print "link.php?data=$data" $file_location $type
  }.GetNewClosure())
  </code></pre>
  
  <p>In the main form the code above works, from popup it doesn't.
  Also tried with no luck.</p>
  
  <pre><code>$print_equip_button.Add_Click({
      Start-Job -ScriptBlock {print "link.php?data=$data" $file_location $type}
  }.GetNewClosure())
  </code></pre>
  
  <p>I've added at the beginning of a function  </p>
  
  <pre><code>for($i=1;$i -le 100;$i++){
      [System.Windows.Forms.Application]::DoEvents()
      start-sleep -s 1
      $LogTextBox.Text = "$temp`n" + "Count $i"
  }
  </code></pre>
  
  <p>to see if what happens to function f1 when I press a button in the popup and from what I can see, when I open the popup form, the counting stops and continues when I close it.</p>
  
  <p>UPDATE:
  I found that if I have the script opened in PowerShell ISE and run it from there, everything works as I wanted without the need of "Start-Job".
  When running the .ps file on its own it doesn't work, not even with "Start-Job"</p>