0

(Read Title)

I honestly have no idea how to do this. I've tried diagnostics.stopwatch, system.timespan , and system.datetime, but I can't wrap my head around how I would do this. Any suggestions?

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Geekitygeek
1

I agree with ddanbe; If you are comfortable with threadign then move the process to a seperate thread from UI and use sleep to pause it between iterations.

Otherwise, you can put the loop into a timers tick event. You would need to amend the way you write your loop though:

//instead of:
for (int i = 0; i < 10; i++)
{
   //do stuff
}

you would need something like:

private int LoopCounter;

private void Button_Click(object sender, EventArgs e)
{
    LoopCounter = 0;
    Timer.Interval = 1000;
    Timer.Start();
}
private void Timer_Tick (object sender, EventArgs e)
{
    if(LoopCounter < 10)
    {
        //do stuff
    }
    else
    {
        Timer.Stop();
    }

    LoopCounter++;
}

It still has all the aspects of your for loop but because you need to increment the counter outside the code block you split down the logic of creating your counter, checking the condition and incrementing the counter.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.