CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2005
    Posts
    121

    increamenting a for loop using seconds

    hi
    how can i increment the for loop with a second seed
    for example
    Code:
    for( ; timer<10 seconds ; timer+=2 seconds )
    {
    
    }
    i need to check for something but after s2 seconds between each check

    i hope you understood me

  2. #2
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: increamenting a for loop using seconds

    Try to use a Timer. I prefer System.Timers.Timer.
    Code:
    Timer t = new Timer(2000);
    t.Elapsed += new EventHandler(timer_Elapsed)
    t.Start()
    
    
    (...)
    
    private void timer_Elapsed(object sender, EventArgs e)
    {
          //do whatever you want
    }

  3. #3
    Join Date
    Jul 2005
    Posts
    121

    Re: increamenting a for loop using seconds

    thanx

    i haven't test it yet(i'm not at home)
    but i have 2 for loops that will be inside each other , so i don't know if the above code will work will
    Code:
    for ( step using seconds)
    {
    if(...){}
    else
    {
    for(step using seconds)
    if(..){}
    else
    {
    ....
    }
    }
    }

  4. #4
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: increamenting a for loop using seconds

    Now that's a bunch of spagetti code.
    Probably you can redesign that method to look better (perhaps not...)

    You can use timers in your case. It's just a matter of having states (maybe you need a state machine?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured