T
T
TechNOIR2018-03-06 10:35:04
PowerShell
TechNOIR, 2018-03-06 10:35:04

Powershell. How to implement background loop execution in a gui script?

Good afternoon.
I ran into a problem, hope you can help me.
There is a GUI script. It implies the constant execution of the cycle in the background of the application. But I don't understand how to do it.
For example, the script:

$form = New-Object WindowsApplication1.Form1
бла бла бла
$form.ShowDialog()

and there is a loop:
while ($ExitFlag -eq $False) {
 Write-Host "новый цикл обработки сообщений" -ForegroundColor Green
}

I'm trying to build a loop so that the form works and it runs in the background.
1. If pasted before Showdialog. That the loop is executed but the form does not open, before loop execution.
2. If put after Showdialog. That fulfills the form if to close it that the cycle begins.
3. If you insert ShowDialog into a loop, then you yourself understand the form cannot be closed and this leads to a freeze.
Any ideas comrades? Thanks in advance!
PS At the same time, the loop must return to the form of the value. That is, in my view, these are 2 threads interacting with each other

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
cicatrix, 2018-03-06
@cicatrix

Maybe try just Show() instead of ShowDialog().
ShowDialog - shows a modal form with blocking further execution until return.
Show will simply show the form and execution will continue.
In this case, the properties and methods of the form itself can be accessed from the calling code.
The disadvantage is that it will be necessary to catch the closing event from the calling code.

A
azarij, 2018-03-06
@azarij

https://stackoverflow.com/questions/49053357/updat...
2 solutions are described here.
Show() instead of ShowDialog()
and using a timer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question