I use named pipes to communicate between an application and a window service, 
but mainly when the application and service run under different credentials or 
sessions. You could do the same thing with your GUI; write one script that runs 
the GUI and another that does your processing (similar to a service or 
webservice) and communicate over pipes. You could have one of your scripts 
launch the other using start-job if you don’t want to fire off two scripts. 
Here is a short example of pipes to give you something to start with. It 
includes both the client and server portions so you would just pull the pieces 
out you need for each (gui and processing). The server pipe would likely be for 
your backend “service” portion, the GUI would be a client. You could run your 
backend code on a more powerful computer and still communicate with pipes. Let 
me know if you need more info or a better example.

Matt

#------pipes------
#load on both client and server:
[reflection.Assembly]::LoadWithPartialName("system.core")


[reflection.Assembly]::LoadWithPartialName("mscorlib")


#open server pipe and name - you can assign pipe direction if wanted:
$pipe = New-Object 
system.IO.Pipes.NamedPipeServerStream("MyPipe",[System.IO.Pipes.PipeDirection]::InOut)

#open streamwriter object on server to write to pipe
$sw = New-Object system.IO.streamwriter($pipe)
$sw.AutoFlush=$true


#open client pipe -
$clipi = New-Object system.IO.Pipes.NamedPipeClientStream("localhost","MyPipe")

#wait for client to connect to pipe - from server console:
$pipe.WaitForConnection()

#connect with client:
$clipi.Connect()

#open streamreader on client:
$sr = New-Object system.io.streamreader($clipi)


#write to pipe from server
$sw.writeline("Hello out there!!!")

#read pipe on client
$sr.ReadLine()

From: [email protected] [mailto:[email protected]] On 
Behalf Of Ryan
Sent: Thursday, February 25, 2016 6:04 PM
To: [email protected]
Subject: Re: [powershell] GUIs and runspaces

Is this WPF or Windows Forms?

When I started writing WinForms, this blog post helped me learn about different 
runspaces and how to make the forms more responsive:  
https://www.sapien.com/blog/2012/05/16/powershell-studio-creating-responsive-forms/

If you are doing it in WPF, I have a series of posts on UI development: 
http://www.ephingadmin.com/better-know-a-powershell-ui/
The "Quack like a duck" post talks about different threads and uses PoshRSJob 
(3rd party cmdlet on GitHub) to do the threading.

Boe Prox (the author of PoshRSJob) has a lot of good information on this also. 
Here's a post about writing data from one thread to another:
http://learn-powershell.net/2012/10/14/powershell-and-wpf-writing-data-to-a-ui-from-a-different-runspace/

Let me know if you need any other resources!


On Thu, Feb 25, 2016 at 4:59 PM Mote, Todd 
<[email protected]<mailto:[email protected]>> wrote:
So I've written a fancy PowerShell script and given it a GUI and it works 
great.  As I add more features to it though, I find that it’s taking longer and 
longer to run and thought I would try to get it to run in a separate thread to 
free up the GUI.  I’m not finding many resources to help me learn how to do 
that. Can anybody point me to any?  I know about sunspaces, bur have not had 
any luck with getting them to work.  Help?

Sent from my Windows 10 phone


================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1
**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be 
used for urgent or sensitive issues 

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

Reply via email to