GUI is Not responding While using a loop

Tagged: , ,

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Ron Ron 2 days, 6 hours ago.

  • Author
    Posts
  • #69210
    Profile photo of Karem Ali
    Karem Ali
    Participant

    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
    Profile photo of Cole
    Cole
    Participant

    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 {
        param($process)
        while ((Get-Process $process).Responding) {Sleep -Milliseconds 1000}
        if (!(Get-Process $process).Responding) {'Do the thing'}
    }
    • #69306
      Profile photo of Karem Ali
      Karem Ali
      Participant

      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
    Profile photo of Ron
    Ron
    Participant

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

    • #69307
      Profile photo of Karem Ali
      Karem Ali
      Participant

      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
      Profile photo of Ron
      Ron
      Participant

      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.