There is a timer code that must be run in a separate thread when the mouse is clicked.
private void button1_Click(object sender, EventArgs e) { Thread tmr = new Thread(TimerStart); tmr.Start(); } private void TimerStart() { date = DateTime.Now; timer1.Interval = 10; timer1.Tick += new EventHandler(TicTimer); timer1.Start(); } private void TicTimer(object sender, EventArgs e) { long tic = DateTime.Now.Ticks - date.Ticks; DateTime stopwath = new DateTime(); stopwath = stopwath.AddTicks(tic); label1.Text = string.Format("{0:HH:mm:ss:ff}", stopwath); } However, nothing happens. If I just call the method:
private void button1_Click(object sender, EventArgs e) { TimerStart(); } works without question. What is the problem?
System.Windows.Forms.Timer. His event is launched in a guay stream. I think you need a timer whose event runs in a separate thread. Take theSystem.Threading.Timer. But do not run it yourself in a separate thread! And yes, you will need to useInvoketo access the controls. - Alexander PetrovInvokedid not understand. It is necessary to add to this line -label1.Text = string.Format("{0:HH:mm:ss:ff}", stopwath);- Sergey