using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Timer
{
public partial class Form1 : Form
{
long count = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void buttonStart_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void buttonStop_Click(object sender, EventArgs e)
{
timer1.Stop();
}
private void timer1_Tick(object sender, EventArgs e)
{
count++;
long hour = count / 3600000;
long min = (count - hour * 3600000)/60000;
long s = (count - hour * 3600000 - min * 60000)/1000;
long ms = (count - hour * 3600000 - min * 60000-s*1000)/1;
label1.Text = String.Format("{0:00}:{1:00}:{2:00}:{3:00}", hour, min, s, ms);
}
}
具体报什么错呢?count数据太小了吧。
有什么问题?注意interval最小值不能小于10ms或者 25ms,具体取决于操作系统
Note that Thread.Sleep(1) won't work because Sleep relinquishes the thread's timeslice. The minimum amount of time a thread will actually stall is determined by the internal system timer but is no less than 10 or 25ms (depending upon OS). There are some special cases but for the most part you should assume that your thread will always stall for at least 10ms. If the interval you specify is less than the system timer's resolution then you might not block at all otherwise it'll be a multiple (plus the latency).