Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Loop -> Wait for user confirmation

Loop -> Wait for user confirmation

Scheduled Pinned Locked Moved C#
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ian Uy
    wrote on last edited by
    #1

    Good Day Sir/Maam, Whats the best way to temporarily stop a loop and wait for a mouse click on a command button before proceeding? while(True) { //Dothis getch(); } Just like the above code, but this time, not a key press but a click event on a command button. Thanks in advance. :)

    M N D 3 Replies Last reply
    0
    • I Ian Uy

      Good Day Sir/Maam, Whats the best way to temporarily stop a loop and wait for a mouse click on a command button before proceeding? while(True) { //Dothis getch(); } Just like the above code, but this time, not a key press but a click event on a command button. Thanks in advance. :)

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, I don't know if it's only me, but I don't like such solutions. I would rather set a flag in the method (where you wanted to wait). Than check this flag at the ButtonClick event, and go on with the code. All the best, Martin

      I 1 Reply Last reply
      0
      • M Martin 0

        Hello, I don't know if it's only me, but I don't like such solutions. I would rather set a flag in the method (where you wanted to wait). Than check this flag at the ButtonClick event, and go on with the code. All the best, Martin

        I Offline
        I Offline
        Ian Uy
        wrote on last edited by
        #3

        Thanks for the reply. I need it to make a program that simulates a sorting algorithm, So I need to show each pass so the user can "WATCH" it. :)

        M 1 Reply Last reply
        0
        • I Ian Uy

          Thanks for the reply. I need it to make a program that simulates a sorting algorithm, So I need to show each pass so the user can "WATCH" it. :)

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          Ok! So remember where you have been in your algorithm, and go an after the method is called again at your button click. All the best, Martin

          1 Reply Last reply
          0
          • I Ian Uy

            Good Day Sir/Maam, Whats the best way to temporarily stop a loop and wait for a mouse click on a command button before proceeding? while(True) { //Dothis getch(); } Just like the above code, but this time, not a key press but a click event on a command button. Thanks in advance. :)

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            You could use a ManualResetEvent or AutoRestEvent. Have the event triggered by the button click.


            only two letters away from being an asset

            1 Reply Last reply
            0
            • I Ian Uy

              Good Day Sir/Maam, Whats the best way to temporarily stop a loop and wait for a mouse click on a command button before proceeding? while(True) { //Dothis getch(); } Just like the above code, but this time, not a key press but a click event on a command button. Thanks in advance. :)

              D Offline
              D Offline
              Dave Herren
              wrote on last edited by
              #6

              What about: while(True) { while(IsLoopPaused == true) { //Add thread.sleep or doevents code here. } getch() } Then have IsLoopPaused set to true when you want to pause and have your button click event set IsLoopPaused to true.

              topcoderjax - Remember, Google is your friend. Try this Custom Google Code Search

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups