//报警 private void OutputMessage(string strMessage) { if (mPaused) { return; } if (!mApplicationRunning) { return; } if (this.listView1.InvokeRequired) { // It's on a different thread, so use Invoke //这在另一个线程中,所以使用委托 OutputMessageCallback d = new OutputMessageCallback(OutputMessage); this.Invoke(d, new object[] { strMessage }); } else { // It's on the same thread, no need for Invoke //这在同一个线程,所以不需要委托 DateTime d = DateTime.Now; String strTime = String.Format("{0}:{1}:{2}:{3}", d.Hour, d.Minute, d.Second, d.Millisecond); ListViewItem item = new ListViewItem(strTime, 0); item.SubItems.Add(strMessage); listView1.Items.Add(item); } }
private void OutputMessage(string strMessage) { if (this.listView1.InvokeRequired) { // It's on a different thread, so use Invoke. OutputMessageCallback d = new OutputMessageCallback(OutputMessage); this.Invoke(d, new object[] { strMessage }); } else { // It's on the same thread, no need for Invoke DateTime d = DateTime.Now; String strTime = String.Format("{0}:{1}:{2}:{3}", d.Hour, d.Minute, d.Second, d.Millisecond); ListViewItem item = new ListViewItem(strTime, 0); item.SubItems.Add(strMessage); listView1.Items.Add(item); } }
private void OutputMessage(string strMessage) { if (this.listView1.InvokeRequired) { // It's on a different thread, so use Invoke. OutputMessageCallback d = new OutputMessageCallback(OutputMessage); this.Invoke(d, new object[] { strMessage}); } else { // It's on the same thread, no need for Invoke DateTime d = DateTime.Now; String strTime = String.Format("{0}:{1}:{2}:{3}", d.Hour, d.Minute, d.Second, d.Millisecond); ListViewItem item = new ListViewItem(strTime, 0); item.SubItems.Add(strMessage); listView1.Items.Add(item); } }