private void Timer_Tick(object sender, EventArgs e) { try { string strCard = LBCardHelper.ReadCardCode(); //string strCard = ReadCardTemp();//测试模拟读卡时用 ReadCount++; if (strCard != "") { this.richTextBox1.AppendText(strCard); this.richTextBox1.AppendText(Environment.NewLine); WriteCardCode(strCard); timer.Enabled = false; this.Close(); } if (ReadCount == 6)//超过6次未读卡成功就自动关闭 { timer.Enabled = false; this.Close(); } } catch (Exception ex) { LBErrorLog.InsertFileLog("LB.ReadCard Timer_Tick:" + ex.Message); this.Close(); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.WindowState = FormWindowState.Minimized; LBCardHelper.StartSerial(); timer = new Timer(); timer.Interval = 1000; timer.Tick += Timer_Tick; timer.Enabled = true; }