Timer Object
-
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
1-Add Timer 2-Set
Enable
Property To true 3-SetInterval
Property to 1000 4-Subscribe toTick
event 5-Add the for loop inTick
event handler MCAD -
1-Add Timer 2-Set
Enable
Property To true 3-SetInterval
Property to 1000 4-Subscribe toTick
event 5-Add the for loop inTick
event handler MCADi'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?
-
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
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
-
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?
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