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. Start/stop button

Start/stop button

Scheduled Pinned Locked Moved C#
databasetutorialquestion
7 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.
  • R Offline
    R Offline
    Rapier503
    wrote on last edited by
    #1

    I am wanting to use a button on a form as a start/stop button for a piece of code. I could put the piece of code in the click function for the button, but is there a better way of achieving this? Via a object of another function? If so how would I trigger the start stop? Please give a code example. Thanks in advance.

    D Q Mircea PuiuM 3 Replies Last reply
    0
    • R Rapier503

      I am wanting to use a button on a form as a start/stop button for a piece of code. I could put the piece of code in the click function for the button, but is there a better way of achieving this? Via a object of another function? If so how would I trigger the start stop? Please give a code example. Thanks in advance.

      D Offline
      D Offline
      drc_no1
      wrote on last edited by
      #2

      Well, my idea would be to use a variable: bool a; ... in the mouse_click event you write: if(a == true) {function_call(var1);} else {function_call(var2);} i did not quite get it what you were doing, but... if that is what you were doing, sorry. in another way i don't know.

      R 1 Reply Last reply
      0
      • R Rapier503

        I am wanting to use a button on a form as a start/stop button for a piece of code. I could put the piece of code in the click function for the button, but is there a better way of achieving this? Via a object of another function? If so how would I trigger the start stop? Please give a code example. Thanks in advance.

        Q Offline
        Q Offline
        quiteSmart
        wrote on last edited by
        #3

        You may use a thread and in the start method of the thread you put your code and when clicking on the strat button you start the thread and you stop it when clicking on the stop button. if you can provide us some code of yours we may help more. good luck

        1 Reply Last reply
        0
        • D drc_no1

          Well, my idea would be to use a variable: bool a; ... in the mouse_click event you write: if(a == true) {function_call(var1);} else {function_call(var2);} i did not quite get it what you were doing, but... if that is what you were doing, sorry. in another way i don't know.

          R Offline
          R Offline
          Rapier503
          wrote on last edited by
          #4

          Thanks, but I don't think this is what I want. I want the code that is started (with the start button) to run continuously (loop within the code) until the stop button is pressed. Thanks

          1 Reply Last reply
          0
          • R Rapier503

            I am wanting to use a button on a form as a start/stop button for a piece of code. I could put the piece of code in the click function for the button, but is there a better way of achieving this? Via a object of another function? If so how would I trigger the start stop? Please give a code example. Thanks in advance.

            Mircea PuiuM Offline
            Mircea PuiuM Offline
            Mircea Puiu
            wrote on last edited by
            #5

            Use a BackgroundWorker and set it to accept cancellation.

            SkyWalker

            R 1 Reply Last reply
            0
            • Mircea PuiuM Mircea Puiu

              Use a BackgroundWorker and set it to accept cancellation.

              SkyWalker

              R Offline
              R Offline
              Rapier503
              wrote on last edited by
              #6

              Thanks BackgroundWorker looks right for the job !!!

              Mircea PuiuM 1 Reply Last reply
              0
              • R Rapier503

                Thanks BackgroundWorker looks right for the job !!!

                Mircea PuiuM Offline
                Mircea PuiuM Offline
                Mircea Puiu
                wrote on last edited by
                #7

                Super :-)

                SkyWalker

                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