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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Timer Object

Timer Object

Scheduled Pinned Locked Moved C#
question
5 Posts 3 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.
  • B Offline
    B Offline
    binglin
    wrote on last edited by
    #1

    I have a foreach loop which checks on a ArrayList I would like to include the Timer object to go through the foreach loop at a 1 second interval. How can I do this? Thanks, BingLin

    M S 2 Replies Last reply
    0
    • B binglin

      I have a foreach loop which checks on a ArrayList I would like to include the Timer object to go through the foreach loop at a 1 second interval. How can I do this? Thanks, BingLin

      M Offline
      M Offline
      Mohamad Al Husseiny
      wrote on last edited by
      #2

      1-Add Timer 2-Set Enable Property To true 3-Set Interval Property to 1000 4-Subscribe to Tick event 5-Add the for loop in Tick event handler MCAD

      B 1 Reply Last reply
      0
      • M Mohamad Al Husseiny

        1-Add Timer 2-Set Enable Property To true 3-Set Interval Property to 1000 4-Subscribe to Tick event 5-Add the for loop in Tick event handler MCAD

        B Offline
        B Offline
        binglin
        wrote on last edited by
        #3

        i've created the object: System.Timers.Timer myTimer = new System.Timers.Timer(1000); I have this: public void start_click(object sender, System.EventArgs e) { //initialise connection to my hardware thru com1 ArrayList frames = this.gCont.GetResponseFrames(); foreach(byte[] frame in frames) { //do my stuffs } } how should i use the timer to check through the foreach loop after the creation of connection and arraylist?

        M 1 Reply Last reply
        0
        • B binglin

          I have a foreach loop which checks on a ArrayList I would like to include the Timer object to go through the foreach loop at a 1 second interval. How can I do this? Thanks, BingLin

          S Offline
          S Offline
          sean_mufc
          wrote on last edited by
          #4

          I am assuming you are writing a Windows App. Basically you click on the timer in the Toolbox panel (in design view) and drag it to the form. Go to timer properties an set Enabled to True and Interval to 1000ms (1s). Double click on the timer icon in design view, This will then switch to your code and it will have added the following: private void timer1_Tick(object sender, System.EventArgs e) { // forech loop and associated code to go here } Put your code inside the method and it will run ever second

          1 Reply Last reply
          0
          • B binglin

            i've created the object: System.Timers.Timer myTimer = new System.Timers.Timer(1000); I have this: public void start_click(object sender, System.EventArgs e) { //initialise connection to my hardware thru com1 ArrayList frames = this.gCont.GetResponseFrames(); foreach(byte[] frame in frames) { //do my stuffs } } how should i use the timer to check through the foreach loop after the creation of connection and arraylist?

            M Offline
            M Offline
            Mohamad Al Husseiny
            wrote on last edited by
            #5

            I told you in the previous post You need to write this code in Timer Tick event handler Not in Command Click event after you set the properties

            private void timer1_Tick(object sender, System.EventArgs e)
            {
            //initialise connection to my hardware thru com1
            
            ArrayList frames = this.gCont.GetResponseFrames();
            
            foreach(byte[] frame in frames)
            {
            //do my stuffs
            }
            }
            
            		
            }
            

            MCAD

            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