Windows PowerShell Advanced Chapter 04 - Working with Forms

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ม.ค. 2025

ความคิดเห็น • 2

  • @DaniSarfati
    @DaniSarfati 10 ปีที่แล้ว +1

    This is a very interesting video, but I believe you may be misguided on the single threading of powershell.
    I found online a script that is able to invoke another thread and have GUI run in the second thread. For me, this is what I need since the script I am developing displays a "Please Wait" dialog box while Powershell is processing something else. I am also planning to use timers for the wait (since start-sleep hangs the GUI).
    Here is an example of how to start another thread in powershell (original source here - www.vistax64.com/powershell/16998-howto-create-windows-form-without-stopping-script-processing.html)
    $rs = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
    $rs.Open()
    # create a variable in the new runspace that also points at the form object.
    # We'll use the same name for simplicity...
    $rs.SessionStateProxy.SetVariable("Form", $form)
    # now create a pipeline in the new runspace that will cause
    # the form to be shown...
    $p = $rs.CreatePipeline( { [void] $Form.ShowDialog() } )
    # close the input stream to the pipe since we don't need it and it will
    # cause the pipeline to block
    $p.Input.Close()
    # Now start the pipeline running asynchronously
    $p.InvokeAsync()

    • @feldyrios
      @feldyrios 10 ปีที่แล้ว

      Remember that these videos were created for version 1 of Powershell and that the PowerShell environment has evolved since then.