A background worker is a different thread than the shape of your window. Therefore, you need your background worker to somehow return information back to the main stream. In the example below, I use the reportProgress function for the background worker, since the event is fired in the window form thread.
public partial class Form1 : Form { enum states { Message1, Message2 } BackgroundWorker worker; public Form1() { InitializeComponent(); worker = new BackgroundWorker(); worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); worker.WorkerReportsProgress = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); } void worker_DoWork(object sender, DoWorkEventArgs e) {
Note: the background worker will not stop at reportProgress. If you want your bgworker to wait until mbox is pressed, you need to do something manually for it.
Marking
source share