.Net Winforms Basic BackgroundWorker Example
I use a BackgroundWorker a lot when working with WinForms in order to perform database or webservice calls without freezing the UI thread. Of course web services can be called using their built in asynchronously methods however when you have a separate data access or model layer, these asynchronous methods are not readily available. On a new project I was working on, I was looking for a basic example online for quick reference but there wasn't one amongst the top search results so I thought I'd post one. using System.ComponentModel; using System.Threading; using System.Windows.Forms; public partial class MainForm : Form { private readonly BackgroundWorker backgroundWorker = new BackgroundWorker(); public MainForm() { this.InitializeComponent(); this.backgroundWorker.DoWork += this.BackgroundWorkerDoWork; this.backgroundWorker.RunWorkerCompleted += this.BackgroundWorkerCompleted; t...