Author Posts

April 21, 2017 at 6:32 pm

i am Using a loop inside my GUI Program , but when the loop starts , i can't teriminate my program or even move it , it halts

so i have to wait until the loop ends so i can move or close the program

the problem is the loop in infinite While(1) , so i can't wait it until it ends 😀

so how can i solve this Problem

April 21, 2017 at 11:23 pm

You would want to run the loop in the background – so you would want to use the Start-Job cmdlet then run your loop inside of it.

$process = 'explorer.exe'

Start-Job -argumentlist $process {
    while ((Get-Process $process).Responding) {Sleep -Milliseconds 1000}
    if (!(Get-Process $process).Responding) {'Do the thing'}

April 22, 2017 at 1:11 am

It depends on what you're doing in the loop but a timer might solve the problem.

April 23, 2017 at 6:46 pm

i can't understand what should i do ,

this code is meaningless for me
why using process explorer and how when it's not responding i do my stuff ?
i am not Dealing with explorer.exe any way i am dealing with my main form and the loop which take action when i submit my needs

April 23, 2017 at 6:47 pm

i dealing with a registry entry , i want it to run for ever , but when user wants to close the program he should be able to and terminate the process , but the form is not responding to terminate it

April 27, 2017 at 1:18 pm

So, yes, a timer should work fine. Add a timer to the form, have it fire every X seconds to perform your action. Your form should be responsive and close when needed.