How to reference variables while multi-threading in this program?

This topic contains 2 replies, has 2 voices, and was last updated by  Poseyj 1 year, 4 months ago.

  • Author
  • #63787


    I'm trying to test a simple GUI app in Powershell and I'm very new to GUIs and threading. I make the GUI in Visual Studio and copy the XAML to Powershell ISE. My ultimate goal is to have a form with text fields that are dynamic, where I type something in and it goes out to check on the internet to see if it's valid.(similar to how websites dynamically check email addresses to see if they're taken), but without hanging the GUI.

    From what I've read, namespaces have the least latency as opposed to Start-job, so I'm attempting to use one to accomplish the work in this, while the user can just tab on. I realize the problem is that in the namespace, it can't see the variables I need to manipulate. So my question is can someone tell me the best direction to go in order to achieve this? Code for this small program is below. Under MAIN, you'll see two commands I want to run. The first one works because it's not in the namespace, the second one fails because it can't see the variable.

    EDIT: it's not letting me post all the code. There's XAML at the top and a line that turns those gui objects into objects, the ones that start with WPF.


    $WPFLabel_1.Content = "Check 1" # This displays

    $code = {$WPFLabel_1.Content = "Check 2"} # This doesn't display
    $newPowerShell = [PowerShell]::Create().AddScript($code)
    $job = $newPowerShell.BeginInvoke()
    While (-Not $job.IsCompleted) {}
    $result = $newPowerShell.EndInvoke($job)


  • #63802

    Max Kozlov

    you need to organize external data exchange between different instances.

    try to check Boe Prox's blog at
    somewhere he describe data exhange with synchronized hash and have alot of wpf samples to learn. btw may be the PoshRSJob module can help you

    • #63874


      Very cool, thanks. Going to try out PoshRSJob

You must be logged in to reply to this topic.