C#: Passing data to BackgroundWorker DoWork Event

Normally, you call the RunWorkerAsync() without an argument to start the background worker. Sometimes you might want to pass some data into the DoWork() function. All you have to do is simply do: RunWorkerAsync(some data) For example, the following code pass an array of string: string[] list = {"one", "two", "three"}; MyBackgroundWorker1.RunWorkerAsync(List); Then you have […]

Thread safe way to update UI elements in C#

//declare the delegate delegate void SetControlValueCallback(Control oControl, string propName, object propValue);   // the function that sets properties on the UI control private void SetControlPropertyValue(Control oControl, string propName, object propValue) { if (oControl.InvokeRequired) { SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue); oControl.Invoke(d, new object[] { oControl, propName, propValue }); } else { Type t = oControl.GetType(); System.Reflection.PropertyInfo[] […]