Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Sending\receiving data to\from powershell runspace

$
0
0

Hello Everyone,

I created separate PS runspace running WPF Form. I'm wondering how can I update the content of RichTextBox control in this runspace from my parent runspace. Is this possible?

My code:

 

# Invoke STA Runspace (WPF works in single thread apartment)
$rpName = "TestName"
$threadSTA = [RunspaceFactory]::CreateRunspace()
$threadSTA.ApartmentState = "STA"
$threadSTA.ThreadOptions = “ReuseThread”
$threadSTA.Open()

# Load WPF assemblies to STA Runspace

$psShell = {Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase}.GetPowerShell()
$psShell.Runspace = $threadSTA
$psShell.Invoke()
$psShell.Commands.Clear()

[void]$psShell.AddScript({
    [XML]$xAML = @'
        <Window Name = "MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Height="353" Width="724" ResizeMode="CanMinimize"
            WindowStartupLocation="CenterScreen" WindowStyle="ThreeDBorderWindow">
   
        <Grid Background="#FF938D8D" OpacityMask="#FFE5E5E5" Opacity="5">
        <RichTextBox HorizontalAlignment="Left" Margin="12,12,0,12"
            Name="logWindow" Width="690" FontFamily="Arial"
            OpacityMask="#FFEBEBEB" Background="#FFFCFCFC" IsReadOnly="True"></RichTextBox>
        </Grid>
        </Window>
'@

$reader=(New-Object System.Xml.XmlNodeReader $xAML)
$Global:Form=[Windows.Markup.XamlReader]::Load( $reader )
[void]$Form.ShowDialog()
}).BeginInvoke()

Thanks.


Viewing all articles
Browse latest Browse all 2562

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>