해상도가 1ms이고 기간이 10ms 인 멀티미디어 타이머를 사용하고 있습니다. 문제는 멀티미디어 타이머가 첫 번째 두 이벤트에 대해 잘못 인터럽트한다는 것입니다. 1ms의 차이가 발생합니다. 이는 내가 원하는 것이 아니기 때문입니다.C#에서 멀티미디어 타이머 인터럽트 (처음 두 인터럽트가 잘못됨)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.mmtimer.Tick += new System.EventHandler(this.mmtimer_Tick);
}
Multimedia.Timer mmtimer = new Multimedia.Timer();
private void Form1_Load(object sender, EventArgs e)
{
mmtimer.Resolution = 1;
mmtimer.Mode = Multimedia.TimerMode.Periodic;
mmtimer.Period = 10;
mmtimer.SynchronizingObject = this;
}
private void S_Click(object sender, EventArgs e)
{
TD.Items.Clear();
MT.Items.Clear();
delta_MT.Items.Clear();
double T = DateTime.Now.Hour * 60 * 60 * 1000 + DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
Point C = Cursor.Position;
TD.Items.Add(C.ToString());
MT.Items.Add(T.ToString());
try
{
mmtimer.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
}
}
private void Stop_Click(object sender, EventArgs e)
{
mmtimer.Stop();
double T = DateTime.Now.Hour * 60 * 60 * 1000 + DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
Point C = Cursor.Position;
TD.Items.Add(C.ToString());
MT.Items.Add(T.ToString());
M();
}
private void mmtimer_Tick(object sender, System.EventArgs e)
{
double T = DateTime.Now.Hour * 60 * 60 * 1000 + DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
Point C = Cursor.Position;
TD.Items.Add(C.ToString());
MT.Items.Add(T.ToString());
}
void M()
{
for (int i = 0; i < MT.Items.Count - 1; i++)
{
double A1 = Convert.ToDouble(MT.Items[i + 1]);
double A2 = Convert.ToDouble(MT.Items[i]);
double d = A1 - A2;
delta_MT.Items.Add(d);
}
}
}
처음 두 개의 인터럽트를 수정하는 방법을 알려주시겠습니까? 만약에 가능하다면.