How to use the same timer for different time intervals?

advertisements

I am using a timer in my code. Status bar updates in tick event on clicking respective button for the time inteval mentioned in properties say one second. Now i want to use the same timer for a different time interval say two seconds for a different oepration. How to achieve that?


I agree with @Henk and others.

But still, something like this could work:

Example

    Int32 counter = 0;

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (counter % 1 == 0)
        {
            OnOneSecond();
        }

        if (counter % 2 == 0)
        {
            OnTwoSecond();
        })

        counter++;
    }

Updated Example

private void Form_Load()
{
    timer1.Interval = 1000; // 1 second
    timer1.Start(); // This will raise Tick event after 1 second
    OnTick(); // So, call Tick event explicitly when we start timer
}

Int32 counter = 0;

private void timer1_Tick(object sender, EventArgs e)
{
    OnTick();
}

private void OnTick()
{
    if (counter % 1 == 0)
    {
        OnOneSecond();
    }

    if (counter % 2 == 0)
    {
        OnTwoSecond();
    }

    counter++;
}