Hello,
I am trying to build a multiform application in PSStudio and the issue I have is that I want to include some of my older tools. I am doing this by having a menustrip with "Tools" in it and the desired tools linked there, calling them via Show-<oldertoolname>_psf, having added the appropriate psf files into the project. All works well, except, I would like to keep the main form interactive when one of these tools are opened, since they are basically standalone. Currently, whenever I open one of the tools, the main form locks until the time the called tool is closed.
Is there a way to avoid this?
Thanks!
Main form locks when child opens.
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Main form locks when child opens.
This is the way PowerShell forms work. PowerShell only allow one modal form to be displayed at a time. The topmost form will be the only one active. PS only allows "ShowDialog" which produces only modal dialogs.
Three are methods using runspaces to launch a modal dialog as a separate PS thread. PowerShell Studio has not built-in support for runspaces so al forms have to be external ps1 files to be called.
Three are methods using runspaces to launch a modal dialog as a separate PS thread. PowerShell Studio has not built-in support for runspaces so al forms have to be external ps1 files to be called.
Re: Main form locks when child opens.
Here is the quick way to launch a form in a separate runspace.
You will have to devise code and a protocol to clean up runspaces that have been ended.
Code: Select all
$f = get-item Function:\Show-TestForm_psf
$ps = [powershell]::Create()
$ps.AddScript($f.Definition)
$ps.BeginInvoke()
Re: Main form locks when child opens.
Hi jvierra,
This is exactly what I was looking for, but being a newb to all this PS GUI stuff, I didn't know whether a job would do the job here ( ) or if something else was the solution.
Anyway, I added a timer that monitors for the child form runspace's IsCompleted and disposes of it when the form is closed.
Thanks a lot for the assist!
This is exactly what I was looking for, but being a newb to all this PS GUI stuff, I didn't know whether a job would do the job here ( ) or if something else was the solution.
Anyway, I added a timer that monitors for the child form runspace's IsCompleted and disposes of it when the form is closed.
Thanks a lot for the assist!