private void ThreadListBox(object listItem) { if (this.listBox.InvokeRequired) //等待异步 { ChangeListBoxText c = new ChangeListBoxText(ThreadListBox); this.listBox.Invoke(c, new object[] { listItem });//通过代理调用刷新方法 } else { ListBoxItem li = listItem as ListBoxItem; listBox.Items.Add(li); listBox.SelectedIndex = listBox.Items.Count - 1; } }
private void ThreadListBox(object listItem) { if (this.listBox.InvokeRequired) //等待异步 { ChangeListBoxText c = new ChangeListBoxText(ThreadListBox); this.listBox.Invoke(c, new object[] { listItem });//通过代理调用刷新方法 } else { if (sameLineCurrent && sameLineLast && listBox.Items.Count > 0) { listBox.Items[listBox.Items.Count - 1] = listItem; } else { ListBoxItem li = listItem as ListBoxItem; listBox.Items.Add(li); listBox.SelectedIndex = listBox.Items.Count - 1; } sameLineLast = sameLineCurrent; sameLineCurrent = false; } }