RE: [scripting] [Powershell] updating WPF UI from a child runspace

2017-03-15 Thread Mote, Todd
I’ve seen some stuff about using an observable collection too, but I couldn’t 
find anything definitive.

At this point I may just go back to process locked winforms, it’s almost not 
worth it.  WPF looks so nice though…

From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On 
Behalf Of Ryan
Sent: Wednesday, March 15, 2017 5:16 PM
To: scripting@lists.myitforum.com
Subject: Re: [scripting] [Powershell] updating WPF UI from a child runspace

The most successful I've been with that in PowerShell was when I used the 
dispatcher timer to update the UI.

The basic idea was to have a synchronized hash table that would exist between 
all the runspaces. I could then store information there for the UI elements and 
the dispatcher timer would update the UI elements if it saw the hashtable 
change.

There's also the ability to use the dispatcher to directly update UI elements 
from a separate thread, but it isn't very optimized in PowerShell. It's fine 
for one-offs, but if you do a lot of calls with it your script will slow down.

I'm trying to think if I have example code somewhere. I'll look for some after 
dinner.

On Wed, Mar 15, 2017 at 4:57 PM Mote, Todd 
<mo...@austin.utexas.edu<mailto:mo...@austin.utexas.edu>> wrote:
Ok, have a WPF form.  It looks pretty.  It runs in its own runspace.  Awesome.  
Now I’m trying to connect UI element actions output to the output box I’ve got. 
 I can update the outputbox fine from the main UI runspace using a nice little 
function using the dispatcher.  But as soon as I have an event fire, like 
combobox.add_selectionchanged, that I want runspaced so I can have the work 
it’s doing separated from the UI, I lose the ability to update the UI runspaces 
output text box.   I’ve tried everything that seems logical to me.  But the 
basic question is how can I edit the UI in a parent runspace from a child 
runspace?

Todd







Re: [scripting] [Powershell] updating WPF UI from a child runspace

2017-03-15 Thread Ryan
The most successful I've been with that in PowerShell was when I used the
dispatcher timer to update the UI.

The basic idea was to have a synchronized hash table that would exist
between all the runspaces. I could then store information there for the UI
elements and the dispatcher timer would update the UI elements if it saw
the hashtable change.

There's also the ability to use the dispatcher to directly update UI
elements from a separate thread, but it isn't very optimized in PowerShell.
It's fine for one-offs, but if you do a lot of calls with it your script
will slow down.

I'm trying to think if I have example code somewhere. I'll look for some
after dinner.

On Wed, Mar 15, 2017 at 4:57 PM Mote, Todd  wrote:

> Ok, have a WPF form.  It looks pretty.  It runs in its own runspace.
> Awesome.  Now I’m trying to connect UI element actions output to the output
> box I’ve got.  I can update the outputbox fine from the main UI runspace
> using a nice little function using the dispatcher.  But as soon as I have
> an event fire, like combobox.add_selectionchanged, that I want runspaced so
> I can have the work it’s doing separated from the UI, I lose the ability to
> update the UI runspaces output text box.   I’ve tried everything that seems
> logical to me.  But the basic question is how can I edit the UI in a parent
> runspace from a child runspace?
>
>
>
> Todd
>
>
>
>
>
>