GUI is Not responding While using a loop

This topic contains 5 replies, has 3 voices, and was last updated by  Ron 1 year, 1 month ago.

  • Author
  • #69210

    Karem Ali

    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

  • #69241


    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'}
    • #69306

      Karem Ali

      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

  • #69246


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

    • #69307

      Karem Ali

      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

    • #69681


      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.

You must be logged in to reply to this topic.