//Make Thread-Safe Calls to Windows Forms Controls private void AddListItemString(string item) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.lstWeatherItemNames.InvokeRequired) { //call itself on the main thread AddListItmCallback d = new AddListItmCallback(AddListItemString); this.Invoke(d, new object[] { item }); } else { //guaranteed to run on the main UI thread this.lstWeatherItemNames.Items.Add(item); } }
//Make Thread-Safe Calls to Windows Forms Controls private void AddListItemString(string item) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.lstWeatherItemNames.InvokeRequired) { //call itself on the main thread AddListItmCallback d = new AddListItmCallback(AddListItemString); this.Invoke(d, new object[] { item }); } else { //guaranteed to run on the main UI thread this.lstWeatherItemNames.Items.Add(item); } }