Skip to content

Instantly share code, notes, and snippets.

@cbcwebdev
Created May 14, 2012 20:33
Show Gist options
  • Save cbcwebdev/2696613 to your computer and use it in GitHub Desktop.
Save cbcwebdev/2696613 to your computer and use it in GitHub Desktop.
Task Parallel Library
public partial class AwesomeSauceForm : Form
{
private Task _theTaskAtHand;
public AwesomeSauceForm()
{
InitializeComponent();
Task.Factory.StartNew(() =>
{
// Do some work if needed, like load data before the function loads, etc.
// This will happen in the thread pool, off the UI thread
Thread.Sleep(1000);
// Begin working with the UI
_theTaskAtHand.Start();
});
// check out MSDN to see what you have access in terms of parameters, I think they can dispatch quite a bit of info to you
_theTaskAtHand = new Task((paramsIfNeeded) => {
textBox1.Text = "From child task";
}, TaskScheduler.FromCurrentSynchronizationContext());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment