Created
August 4, 2010 15:10
-
-
Save thedersen/508277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Form : System.Windows.Forms.Form | |
{ | |
public Form() | |
{ | |
InitializeComponent(); | |
} | |
private void buttonStart_Click(object sender, EventArgs e) | |
{ | |
StartAsyncJob(); | |
} | |
private void StartAsyncJob() | |
{ | |
var worker = new Worker(SynchronizationContext.Current); | |
backgroundWorker.DoWork += (sender, e) => worker.DoWork(); | |
backgroundWorker.RunWorkerAsync(); | |
} | |
} | |
public class Worker | |
{ | |
private readonly SynchronizationContext _synchronizationContext; | |
public Worker(SynchronizationContext synchronizationContext) | |
{ | |
_synchronizationContext = synchronizationContext; | |
} | |
public void DoWork() | |
{ | |
_synchronizationContext.Send(callback => MessageBox.Show("Hello from background worker!"), null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment