private void OnRegChanged(object sender, EventArgs e) { if (listBox1.InvokeRequired) { listBox1.BeginInvoke(new EventHandler(OnRegChanged), new object[] { sender, e }); return; } listBox1.Items.Add("Registry has changed"); }
/// <summary> /// 跨线程清除listbox的item /// </summary> /// <param name="lb"></param> public void CrossThreadClearListboxItem(ListBox lb) { if (lb.InvokeRequired) { DelegateforClearListboxItem del = new DelegateforClearListboxItem(CrossThreadClearListboxItem); lb.BeginInvoke(del, new object[] { lb }); } else { lb.Items.Clear(); } }
public void Remove(ClientInfo item, ListBox list) { if (list.InvokeRequired) { list.BeginInvoke(new MethodInvoker(delegate { Remove(item, list); })); } else { list.Items.Remove(item); } }
public string GetSelectedListBoxIdx(ListBox anything, int idx) { string rStr = string.Empty; anything.BeginInvoke((MethodInvoker)delegate { try { rStr = (string) anything.Items[idx]; } catch { } }); return rStr; }
private void UpdateClientListControl() { if (InvokeRequired) // Is this called from a thread other than the one created // the control { // We cannot update the GUI on this thread. // All GUI controls are to be updated by the main (GUI) thread. // Hence we will use the invoke method on the control which will // be called when the Main thread is free // Do UI update on UI thread listBoxClientList.BeginInvoke(new UpdateClientListCallback(UpdateClientList), null); } else { // This is the main thread which created this control, hence update it // directly UpdateClientList(); } }
void NetComCallbackSE(Object sender, MNetCom.MSERec records, int numRecords, string objectName) { //since we passed the this pointer to the callback object, we can assume that the sender //is of type NetComExampleStreamsForm. NetComExampleStreamsForm thisClass = (NetComExampleStreamsForm)sender; //add the object name to the textbox string msgString; msgString = "Received SE Record For: " + objectName + " at DAS TS " + records.qwTimeStamp.ToString(); // Update UI on the UI thread using delegate. AsyncRecordLogUpdate RecordLogUpdateDelegate = new AsyncRecordLogUpdate(RecordLogUpdate); lbRecordLog.BeginInvoke(RecordLogUpdateDelegate, new Object[] { msgString }); }
public void SetSelectedListBoxIdx(ListBox anything, int idx, bool state) { anything.BeginInvoke((MethodInvoker)delegate { try { anything.SetSelected(idx, state); } catch { } }); }
/// <summary> /// 实现跨线程插入到Listbox中数据的函数 /// </summary> /// <param name="lb"></param> /// <param name="strMsg"></param> public void CrossTreadAddItemtoListbox(ListBox lb, string strMsg) { if (lb.InvokeRequired) { DelegateforAddItemToListbox del = new DelegateforAddItemToListbox(CrossTreadAddItemtoListbox); lb.BeginInvoke(del, new object[] { lb, strMsg }); } else { lb.Items.Add(strMsg); } }
private void ShowInfoProc(string strMsg, ListBox lstBox, int nMax) { lstBox.BeginInvoke((Action)delegate () { lstBox.BeginUpdate(); lstBox.Items.Add(strMsg); if (nMax > 0) { while (lstBox.Items.Count > nMax) lstBox.Items.RemoveAt(0); } // Scroll to end // lstBox.SelectedIndex = lstBox.Items.Count - 1; lstBox.EndUpdate(); }); }
private void ListboxItemsInsert(ListBox lb, string strVal) { if (lb.InvokeRequired) { dListboxItemsInsert d = new dListboxItemsInsert(ListboxItemsInsert); lb.BeginInvoke(d, new object[] { lb, strVal }); } else { lb.Items.Add(strVal); } }
private void ListBoxItemsDelete(ListBox lb) { if (lb.InvokeRequired) { dListBoxItemsDelete d = new dListBoxItemsDelete(ListBoxItemsDelete); lb.BeginInvoke(d, new object[] { lb }); } else { lb.Items.Clear(); } }