简体   繁体   中英

Timer doesn't raise during long event

I am trying to present to operator timer 00:00 on the start button event ( that start my program - long time event ) I enabled the timer but it doesn't tick only when the event finished or if message box occur .

I am using C# form timer .

Any idea how to implement in C# timer during long event ? I think is related to threading timer ? Any Example ? Please help ! thanks

private void Timer_elapsed_Tick(object sender, EventArgs e)
    {
        timeSec++;
        if(timeSec >= 60)
        {
            timeSec = 0;
            timeMin++;
        }
        DrawTime();
    }

    private void DrawTime()
    {
        lbSec.Text = string.Format("{0:00}", timeSec);
        lbMin.Text = string.Format("{0:00}", timeMin);
    }

private void start_Click(object sender, EventArgs e)
    {
      timer_elapsed.Enabled = true;
      //do some event (long time) 
      //timer not works during this event 


    }
// when the event finished timer works 

I think timer control not associated with Tick event. check your your code form designer cs whether you configured wired events handlers correctly for "Timer_elapsed_Tick". this.timer_elapsed.Tick += new System.EventHandler(this.Timer_elapsed_Tick);

solutions: 1.To works with System.Timers.Timer and not the windows form timer . 2.Add on click event Application.DoEvents .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM