日期:2014-05-18 浏览次数:21246 次
serialsReceiveThread.Suspend();
private void btnListTags_Click(object sender, EventArgs e) { try { if (btnListTags.Text == "Close") { btnListTags.Text = "Open"; btnListTags.Enabled = true; timer1.Enabled = false; serialsReceiveThread.Suspend(); } else { timer1.Enabled = true; btnListTags.Text = "Close"; //开启接收线程 serialsReceiveThread = new Thread(new ThreadStart(serialThreadReceive)); serialsReceiveThread.Start();//开始接收线程 } } catch (Exception ex) { } }
private void serialThreadReceive() { int lenStr = 0; int recvlen; byte[] buffer = new byte[1024]; int offset = 0; int count = 2; while (true) { try { recvlen = sl.readDatas(ref buffer, offset, count); } catch { break; } Dosomething() //解码过程 doPCstring(buffer);// 将解码过的数据,准备处理后显示到listView控件上 } }
private void doPCstring(byte[]buf) { Dosomething()// 就是将字节数组内内容,并接成字符串 if (PCs != "") { showPCToListView(PCLen, PCs, idLen, IDS, userLen, Users, tsNo); // 将字符串,显示到listView 控件上 } }
private void showPCToListView(string PCLen,string PCs,string idLen,string IDS,string userLen,string Users,string tsNo ) { if (!listView1.InvokeRequired) { if (listView1.Items.Count < 1)// 如果 listview上的记录为空 则添加一个记录; { dosomething () } else { Dosomething() } }//!listView1.InvokeRequired