Posts

Showing posts from January, 2022

WPF Multithreading: Using the BackgroundWorker and Reporting the Progress to the UI

 In this blog ,    I am going to show you how to create a multithreaded application that shows a progress dialog which shows real time progress to the user. First lets start with how to get started with multithreading in WPF. If you don’t want to read how this actually works and just want to get the source and start playing ,here is the Running a Background Process The RunWorkerAsync method starts the execution of the background process by raising the DoWork event. The code in the DoWork event handler is executed on a separate thread. int maxRecords = 1000;   BackgroundWorker worker = new BackgroundWorker();   worker.DoWork += delegate ( object s, DoWorkEventArgs args) { for ( int x = 1; x < maxRecords; x++) { System.Threading.Thread.Sleep(10); } };   worker.RunWorkerAsync(); Providing Parameters to the Process Your background process may required one or more parameters, such as the address of a file to download. You can provide a parameter in the RunW