title: PowerShell Loading Animation
body: <p>I would like to create a GUI that shows a loading bar while a job is running in the background. For simplicity, I've made the job an infinite loop so it should always be running. I've only included necessary parts of the code:</p>
  
  <pre><code>$Label = new-object system.windows.forms.Label
  $Label.Font = 'Ariel,12pt'
  $Label.Text = ""
  $Label.AutoSize = $True
  $Label.Location = new-object system.drawing.size(50,10)
  $Form.Controls.Add($Label)
  
  $LoadingAnimation = @(".....","0....",".0...","..0..","...0.","....0",".....")
  $AnimationCount = 0
  
  $test = start-job -Name Job -ScriptBlock { for($t=1;$t -gt 0; $t++){} }
  while ($test.JobStateInfo.State -eq "Running")
  {
      $Label.Text = $LoadingAnimation[($AnimationCount)]
      $AnimationCount++
      if ($AnimationCount -eq $LoadingAnimation.Count){$AnimationCount = 0}
      Start-Sleep -Milliseconds 200
  }
  </code></pre>
  
  <p>Upon testing this code in the console, just using Write-Host instead of $Label.Text, it works just fine. What needs to be done differently to get this to work in a windows form created by PowerShell?</p>