0

I'm searching how I could check if a winform form is opened with Powershell, like this response for VB.net. I'm working with two runspaces, and I need to start the second, when my form is opened.

My first runspace is for the GUI. When the UI creation is completed, I opened it

$CommonHashTable.MainForm.ShowDialog()

And then, I'm trying to test if this form is opened (snipet from VB.net) from PowerShell main thread:

If Application.OpenForms().OfType(Of $CommonHashTable.MainForm).Any Then
 ... startsecondrunspace
Community
  • 1
  • 1
mrplume
  • 183
  • 1
  • 3
  • 18
  • 1
    What exactly is your question / problem? Do you struggle with 'translating' the last snippet `If Application.OpenForms().OfType ...` to PoSh? – DAXaholic Sep 09 '16 at 11:08
  • Yes, I'm searching how to convert in Powershell this sample – mrplume Sep 09 '16 at 11:43

2 Answers2

1

A better way to test if the form is open might be to

if ($CommonHashTable.MainForm.IsHandleCreated) {
    startsecondrunspace
}

Application.OpenForms() would be a method on an Application Class rather than the Form class. I am unsure if there is an instance of the Application class to even be able to use that method. If there was, I would imagine it should look something like this:

If ($ApplicationObject.OpenForms().OfType(Of $CommonHashTable.MainForm).Any) {
    startsecondrunspace
}
BenH
  • 9,766
  • 1
  • 22
  • 35
0

Thanks you very much, I have created this function :

do {
    RecordToLog -Message "Waiting..."
    start-sleep -m 100
} until ($CommonHashTable.MainForm.IsHandleCreated)
startsecondrunspace

It's working.

mrplume
  • 183
  • 1
  • 3
  • 18