WPF UI running in seperate runspace - able to set/get controls via synchronized hash table, but referencing the control via the hash table from within an event handler causes both runspaces to hang.

I am trying to build a proof of concept where a WPF form is hosted in a seperate runspace and updates are handled from the primary shell/runspace. I have had some success thanks to a great article by Boe Prox, but I am having an issue I wanted to open up
to see if anyone had a suggestion.
My goals are as follows:
1.) Set control properties from the primary runspace (Completed)
2.) Get control properties from the primary runspace (Completed)
3.) Respond to WPF form events in the UI runspace from the primary runspace (Kind of broken).
I have the ability to read/write values to the form, but I am having difficulty with events. Specifically, I can fire and handle events, but the minute I try to reference the $SyncHash from within the event it appears to cause a blocking condition hanging both
runspaces. As a result, I am unable to update the form based on an event being fired by a control.
In the example below, the form is loaded and the following steps occur:
1.) Update-Combobox is called and it populates the combobox with a list of service names and selects the first item.
2.) update-textbox is called and sets the Text property of the textbox.
3.) The Text value of the textbox is read by the function read-textbox and output using write-host.
4.) An event handle is registered for the SelectionChanged event for the combobox to call the update-textbox function used earlier.
5.) If you change the selection on the combobox, the shell and UI hangs as soon as $SyncHash is referenced. I suspect this is causing some sort of blocking condition from multiple threads trying to access the synchronized nature of the hash table, but I am
unsure as to why / how to work around it. If you comment out the line "$SyncHash.TXT_Output.Dispatcher.Invoke("Send",[action]{$SyncHash.TXT_Output.Text = $Value})" within update-textbox the event handler will execute/complete.
$UI_JobScript =
try{
Function New-Form ([XML]$XAML_Form){
$XML_Node_Reader=(New-Object System.Xml.XmlNodeReader $XAML_Form)
[Windows.Markup.XamlReader]::Load($XML_Node_Reader)
try{
Add-Type –AssemblyName PresentationFramework
Add-Type –AssemblyName PresentationCore
Add-Type –AssemblyName WindowsBase
catch{
Throw "Unable to load the requisite Windows Presentation Foundation assemblies. Please verify that the .NET Framework 3.5 Service Pack 1 or later is installed on this system."
$Form = New-Form -XAML_Form $SyncHash.XAML_Form
$SyncHash.Form = $Form
$SyncHash.CMB_Services = $SyncHash.Form.FindName("CMB_Services")
$SyncHash.TXT_Output = $SyncHash.Form.FindName("TXT_Output")
$SyncHash.Form.ShowDialog() | Out-Null
$SyncHash.Error = $Error
catch{
write-host $_.Exception.Message
#End UI_JobScript
#Begin Main
add-type -AssemblyName WindowsBase
[XML]$XAML_Form = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<DataTemplate x:Key="DTMPL_Name">
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</Window.Resources>
<DockPanel LastChildFill="True">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<Label Name="LBL_Services" Content="Services:" />
<ComboBox Name="CMB_Services" ItemTemplate="{StaticResource DTMPL_Name}"/>
</StackPanel>
<TextBox Name="TXT_Output"/>
</DockPanel>
</Window>
$SyncHash = [hashtable]::Synchronized(@{})
$SyncHash.Add("XAML_Form",$XAML_Form)
$SyncHash.Add("InitialScript", $InitialScript)
$Normal = [System.Windows.Threading.DispatcherPriority]::Normal
$UI_Runspace =[RunspaceFactory]::CreateRunspace()
$UI_Runspace.ApartmentState = [System.Threading.ApartmentState]::STA
$UI_Runspace.ThreadOptions = [System.Management.Automation.Runspaces.PSThreadOptions]::ReuseThread
$UI_Runspace.Open()
$UI_Runspace.SessionStateProxy.SetVariable("SyncHash",$SyncHash)
$UI_Pipeline = [PowerShell]::Create()
$UI_Pipeline.Runspace=$UI_Runspace
$UI_Pipeline.AddScript($UI_JobScript) | out-Null
$Job = $UI_Pipeline.BeginInvoke()
$SyncHash.ServiceList = get-service | select name, status | Sort-Object -Property Name
Function Update-Combobox{
write-host "`nBegin Update-Combobox [$(get-date)]"
$SyncHash.CMB_Services.Dispatcher.Invoke($Normal,[action]{$SyncHash.CMB_Services.ItemsSource = $SyncHash.ServiceList})
$SyncHash.CMB_Services.Dispatcher.Invoke($Normal,[action]{$SyncHash.CMB_Services.SelectedIndex = 0})
write-host "`End Update-Combobox [$(get-date)]"
Function Update-Textbox([string]$Value){
write-host "`nBegin Update-Textbox [$(get-date)]"
$SyncHash.TXT_Output.Dispatcher.Invoke("Send",[action]{$SyncHash.TXT_Output.Text = $Value})
write-host "End Update-Textbox [$(get-date)]"
Function Read-Textbox(){
write-host "`nBegin Read-Textbox [$(get-date)]"
$SyncHash.TXT_Output.Dispatcher.Invoke($Normal,[action]{$Global:Return = $SyncHash.TXT_Output.Text})
$Global:Return
remove-variable -Name Return -scope Global
write-host "End Read-Textbox [$(get-date)]"
#Give the form some time to load in the other runspace
$MaxWaitCycles = 5
while (($SyncHash.Form.IsInitialized -eq $Null)-and ($MaxWaitCycles -gt 0)){
Start-Sleep -Milliseconds 200
$MaxWaitCycles--
Update-ComboBox
Update-Textbox -Value $("Initial Load: $(get-date)")
Write-Host "Value Read From Textbox: $(Read-TextBox)"
Register-ObjectEvent -InputObject $SyncHash.CMB_Services -EventName SelectionChanged -SourceIdentifier "CMB_Services.SelectionChanged" -action {Update-Textbox -Value $("From Selection Changed Event: $(get-date)")}

Thanks again for the responses. This may not be possible, but I thought I would throw it out there. I appreciate your help in looking into this.
To clarify the "Respond to control events in the main runspace"... I'm would like to have an event generated by a form object in the UI runspace (ex: combo box selectionchanged event) trigger a delegate within the main runspace and have that delegate in
the main runspace update the form in the UI runspace.
ex:
1.) User changes selection on combo box generating form event
2.) Event calls delegate (which I have gotten to work)
3.) Delegate does some basic processing (works)
4.) Delegate attempts to update form in UI runspace (hangs)
As to the delegates / which runspace they are running in. I see the $synchash variable if I run get-var within a delegate, but I do not see the $Form variable so I am assuming that they are in the main runspace. Do you agree with that assumption?

Similar Messages

  • Why is my iPod touch able to see my iMac as a wireless router but can't actually share the connection properly?

    So I've set up Ethernet Internet Sharing via my iMac, and my iPod Touch and other devices can see the network. I type in the password, it succeeds but instead of a tick appearing I get the grey loading wheel forever. Why can I 'connect' to the network but not actually gain internet access? I've even tried no password and the same thing happens.
    Thanks for your time.

    i have same problem if i close sharing and reoopen my sharing i get a 1-5 minute connection
    not sure 1-5 minutes is helpful but if i solve it i will let you know

  • TS4268 Ever since I uploaded i0s7 I haven't been able to receive I messages or face time. I have took it to the apple store and they couldn't figure it out. I have also followed the trouble shooting from I tunes and still can't get it working

    Ever since I uploaded i0s7 I haven't been able to receive I messages or face time. I have took it to the apple store and they couldn't figure it out. I have also followed the trouble shooting from I tunes and still can't get it working

    Hi,
    Strikes -
    Go into compositionReady and have 3 variables you will be able to set them like this
    strike1 = 0;
    strike2 = 0;
    strike3 = 0;
    So on the wrong item click have
    if(strike1 == 0) {
    PLAY STRIKE1 ANIMATION
    strike1 = 1;
    else if(strike2 == 0) {
    PLAY STRIKE2 ANIMATION
    strike2 = 1;
    else if(strike3 == 0) {
    PLAY STRIKE2 ANIMATION
    strike3 = 1;
    So this will make it so when the wrong item is clicked each strike will be played in order.
    Random Scrolling -
    You should look into the Math.Random function to make things random in edge.
    This is an example of the Random function. It will generate a random number up to 100.
    var random = Math.floor (Math.random () * 100);
    Lose Screen Score -
    So we can create another variable in compositionReady for the lose score.
    score = 0;
    Now when the user gains a point to add to the score you could do this code on the click
    score++;
    which would add 1 to the score, However you can add however much you like to the score doing "score + 2" and so on.
    To edit a text with the score at the end which I'm assuming you will want to do you will use .html
    so $("Text").html("You score is " + score);
    I hope this helps!

  • Not able to see the tree on the jspx page after running

    Hi All,
    This is something strange.I am dragging the VO on the page fragment from the data control as adf tree. And I am using the panel collection as component for adf tree.
    After running the jspx when I am moving to the fragment I am not able to see the tree.
    However when I am running the AM it is working properly for the view objects and view link used to populate the tree.
    Can anybody put some thoughts on this.
    Thanx
    Kanika

    Thnx for your replies..
    I am dropping taskflow as region . I am not using the switcher component.
    On left side of the page the tree is visible now. but the taskflow is not refreshing on the click of the tree node based on the value of the node.
    Please advice how to accompolish this now??

  • I was running Firefox on another computer that lost it's motherboard, was able to salvage the harddrive, but my mail files on the older hard drive have a different name, how can I pull or import those older files into firefox running on another computer?

    I had been running other email clients for years and finally switched to Firefox. All the while importing my other email folders. So I had quite a large history of email. I had been backing up my system using Acronis for years. My desktop's motherboard crashed and was not worth repairing. I pulled my desktop hard drive and turned it in a standalone drive. I re-established my email on a laptop starting from scratch using Firefox. I would like to import (if possible) the emails history that is stored on the standalone drive (formerly my old hard drive). However, the names of the mail folders on the drives are different. For example: current computer the mail folder is named garlic.com. On the standalone drive (old hard drive) there are several folders and they are named, for instance; mail.garlic.com, mail.garlic-1.com , and so forth. it goes up through garlic-4.com.
    How can I pull or import these older folders into my current email folder and see all my old email archives?

    You are not going to be able to run your old system from the backup on this old computer as the hardware is incompatible.
    You need to get a new computer or a refurbished one.

  • I have a new iMac running iTunes 10.4 in OS 10.6.8, and a new Mac Air running iTunes 10.4 in Lion.  I was able to transfer all my music etc. from the iMac onto the Air, but cannot figure out how to get the Playlists from the iMac to the Air.  iTunes Help

    I have a new iMac running iTunes 10.4 in OS 10.6.8, and a new Mac Air running iTunes 10.4 in Lion.  I was able to transfer all my music etc. from the iMac onto the Air, but cannot figure out how to get the Playlists from the iMac to the Air.  iTunes Help says File >Library >Export playlist and choose XML, or to save a copy of all your playlists, File > Library > Export Library, "the Exported info is saved in XML format."  Then it says, "to import an iTunes playlist, File > Library > Import Playlist".  Now I am assuming I do that import part on the Air, but when I try it doesn't recognize anything that can be imported - what am I missing??? Aside from a clue...

    Thanks, Jim, for taking the time, but the reply is unfortunately vague in the exact area of my confusion!  "you need to copy that file to your new computer..."  Well, the Import/Export instructions make it seem as if the two computers should be able to communicate this file thru wifi, but that's the linkage I can't seem tocreate with Import/Export.  Should I instead email a copy to myself (thats what applecare suggested)?  Copy it to and from a thumb drive?  But then place the file where?  And the article was helpful, but should I be trying to move the Library file or the Library.xml file (as iTunes Help suggests)?  Sorry to be so clueless about it...I suppose I buy Apple in the hopes of not having to think about this stuff, which approach seems not to be serving me well. Thanks again for your time!

  • I am running lion now and I am not able to safe my emails to the computer with the attachments. what's wrong?

    I am running lion now and I am not able to safe my emails to the computer with the attachments. what's wrong?

    Try using these settings: http://support.apple.com/kb/HT4864.

  • I bought a new MacBookPro moved everything from old MacBookPro, new machine runs 10.6.7 - but iPhoto won't 'upgrade' the library - just hangs up supposedly while writing new library. help. thanks.

    i bought a new MacBookPro moved everything from old MacBookPro, new machine runs 10.6.7 - but iPhoto won't 'upgrade' the library - just hangs up supposedly while writing new library. help. thanks.

    How did you "move everything" over?
    Migration assistance does not handle the iPhoto library well sometimes - the best way is to drag the bad iphoto library from the pictures folder on the new system to the desktop, connect the two systems together (network, firewire target mode, etc) and drag the iPhoto library intact as a single entity from the old system to the pictures folder of the new system and launch iPhoto on the new system - it will open and convert the iPhoto library as necessary and you will be fine - once you test the iPhoto library you can delete the one on the desktop
    LN

  • I've got a  MacBook Pro 1TB HD, the drive was damaged (probably dropped) after I formatted the new drive I was able to get the OSi onto the drive and it's now up and running..But prior to removing the old HD I was able to run CloneZilla to map t

             
        I've got a  MacBook Pro 1TB HD, the drive was damaged (probably dropped) after I formatted the new drive I was able to get the OSi onto the drive and it's now up and running..But prior to removing the old HD I was able to run CloneZilla to map the drive. The problem I'm having is getting the files and documents back on the new HD.
       I created a folder on the desk top and moved all the files and docs onto it, ( files / docs was originally burnt on a DVD ).  I'm not sure A) how to open the specific files B) which files to extract C) Is it as simple as drag and drop...
       Hope you're able to understand my problem and offer some suggestions, in advance thank you for your time and effort...

    Hi, Steve -
    Yes, the CD-ROM drive must be jumpered as Master in order for it to be bootable.
    Your G4 (PCI) should have two built-in IDE buses - one is usually assigned to the CD-ROM and Zip drives, and the other is used for hard drives. If you have the hard drive connected to the same bus as the one the CD-ROM is on, try switching the hard drive to the other bus.
    Set the hard drive's jumpers as Master.
    Exception - if the hard drive is a Western Digital, it may have a third position, Single, which must be used when the drive is the only device on the bus.
    Note - Cable Select jumper settings will not work on a G4 (PCI).
    Edit - -
    Startup Manager, which is what booting with Option held down invokes, is not available on a G4 (PCI).
    Article #106178 - Startup Manager: How to Select a Startup Volume
    Firewire Target Disk Mode is limited on a G4 (PCI) - it can be the Host machine, but not the Target machine.
    Article #58583 - Firewire Target Disk Mode
    Relatedly, a G4 (PCI) can not boot to firewire drives, although it can use them for storage.
    Article #58606 - FireWire Booting

  • I have a I-mac that is not able to upgrade the os past 10.7.5, when I go to upgrade Pages it says i have to be running os 10.10, how can I get Pages that will run with os 10.7.5.

    I have a I-mac that is not able to upgrade the os past 10.7.5, when I go to upgrade Pages it says i have to be running os 10.10, how can I get Pages that will run with os 10.7.5.

    Click here and follow the instructions. If they’re not applicable, buy an iWork 09 DVD from a source such as Amazon or eBay.
    (116937)

  • I cannot access my Apple TV in WiFi mode. I have used it previously, but it keeps saying it is not connected to the network. My broadband is running. I was able to access Apple TV using an Ethernet cable. I have entered the password as confirmed by my ISP

    I cannot access my Apple TV in WiFi mode. I have used it previously, but it keeps saying it is not connected to the network. My broadband is running. I was able to access Apple TV using an Ethernet cable. I have entered the wireless password as confirmed by my ISP without any success.

    Hi,
    Thanks for trying to solve my problem. It appears that the password I was inserting was incorrect. I now have access.
    Thanks again.

  • Can I run two seperate PID functions in one VI

    I need to controll two different valves. THey must be run by a PID function. Can I run two seperate PID modules? If so do they need to be in the same while loop?
    Solved!
    Go to Solution.

    Hi,
    yes, you can run 2 PID functions in one VI.
    No, they don't need to be in the same loop.
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • I recently developed an application for my company and now they would like the applications to run on all their ipads and samsung galaxies. I was able to put the app on the Samsungs however though I have no idea how I can get it on the ipad

    I recently developed an application for my company and now they would like the applications to run on all their ipads and samsung galaxies. I was able to put the app on the Samsungs however though I have no idea how I can get it on the ipad

    Go to this website and read the information. If you can't find a link to anything that's appropriate for your needs, click on the support link at the top.
    https://developer.apple.com/programs/ios/

  • I have an iMac with Safari; will i be able to run LiveCycle and Designer?  I cannot get past acceptance page.

    I have an iMac with Safari; will i be able to run LiveCycle and Designer?  I cannot get past acceptance page.  I want to use and update forms and it says I need Designer.  I was trying the trial version but am having problems.

    Is there an actual individual who can give me guidance?  This "leave a question and come back days later" does not help.

  • How can I create "drop caps" Anchored frames tool: "Run into Paragraph" in a text document, and at the same time be able to feather the text to the bottom of the pages? I´m using FrameMaker 10.

    @

    Presumably you are doing the DC as a single letter inside an Anchored Frame run-in from left.
    Back when FM had a manual, this was the method discussed in the manual. The manual, however, also said "Framemaker does not feather text in a text frame in which text runs around graphics."
    That was FM7.0. I don't know if FM has enhanced DC or feathering since then.
    If I had the requirement, I might look at putting the whole lead paragraph in a borderless table.

Maybe you are looking for

  • How can I transfer my apps bought in iTunes from my iPod, or MBP to my windows PC

    I have purchased apps from Itunes. I want to copy them from my Ipod Touch 3rd gen, or from my MBP and put them onto my windows pc. for later upload to an android tablet. Can this be done?

  • Buying a hard drive

    I'm looking into buying a new [external] hard drive and I don't know what to look for aside from the capacity. I hope you guys can answer my questions below... - IDE or SATA? What's the difference and what should I get? - 8MB or 16MB? Obviously 16 is

  • Remove extended features more than one document at a time.

    Does anybody know how to remove the extended features in Adobe files in batch mode? Since the newest upgrade of Adobe reader, we are having to remove the extended features and have 702 forms to do this with! Our users are trying to add their image si

  • SAP LSO Content Player Error

    Hi All, We are in the process of upgrading SAP to 6.0. We also upgrade our LSO from 300 to 600 including the Authoring Environment and the Content Management System. Now, after we publish the course via the Authoring Environment/Repository Explorer a

  • Web Dynpro ABAP call transaction in the foreground

    In Screen Painter/SAP ALV, we can create a screen where for example if you double click on a sales order field it can take you a VA03 transaction by : call transaction VA03 ... and skip first screen. I am creating Web Dynpro ABAP application that nee