我需要等待来自并口的一个高电平,用了一个while循环。然后如果十秒钟内这个电平还不来的话,就取消等待。但是,我把while循环加上以后,Timer就进不了Tick了,去掉那个等待的话,可以进Tick。请问是怎么回事呢? .......初始化
while (d == 0)//这里等待并口信号
{
WinIO.GetPortVal((IntPtr)0x378, out d, 1);
}
} private void timer1_Tick(object sender, EventArgs e)
{
int temp = Convert.ToInt32(lb_TimeCounter.Text);
temp = temp - 1;
lb_TimeCounter.Text = Convert.ToString(temp);
lb_TimeCounter.Refresh();
if (temp == 0)
this.Close();
}
while (d == 0)//这里等待并口信号
{
WinIO.GetPortVal((IntPtr)0x378, out d, 1);
}
} private void timer1_Tick(object sender, EventArgs e)
{
int temp = Convert.ToInt32(lb_TimeCounter.Text);
temp = temp - 1;
lb_TimeCounter.Text = Convert.ToString(temp);
lb_TimeCounter.Refresh();
if (temp == 0)
this.Close();
}
但是我原先的想法怎么就实现不了呢。加上while循环,就不进Tick了。
while ((d&0xFF) == 0xFF)//等待触发信号
{
WinIO.GetPortVal((IntPtr)0x378, out d, 1);
TimeDiff = DateTime.Now - DT;
lb_TimeCounter.Text = Convert.ToString(10-TimeDiff.Seconds);
lb_TimeCounter.Refresh();
if (TimeDiff.Seconds == 10) break;
}
this.Close();
{
WinIO.GetPortVal((IntPtr)0x378, out d, 1);
Application.DoEvents();
}
{
WinIO.GetPortVal((IntPtr)0x378, out d, 1);
Application.DoEnvent();
}
stop = false; while (d == 0 )//这里等待并口信号
{
WinIO.GetPortVal((IntPtr)0x378, out d, 1);
Application.DoEvents();
if (stop==true) break;
}
} private void timer1_Tick(object sender, EventArgs e)
{
int temp = Convert.ToInt32(lb_TimeCounter.Text);
temp = temp - 1;
lb_TimeCounter.Text = Convert.ToString(temp);
lb_TimeCounter.Refresh();
if (temp == 0)
Stop = true;
}