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
2
  • 1
    What exactly is your question / problem? Do you struggle with 'translating' the last snippet If Application.OpenForms().OfType ... to PoSh? Commented Sep 9, 2016 at 11:08
  • Yes, I'm searching how to convert in Powershell this sample Commented Sep 9, 2016 at 11:43

2 Answers 2

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
}
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.