Skip to content

Instantly share code, notes, and snippets.

@CosminLazar
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CosminLazar/d3cfe254cd203c66fdb5 to your computer and use it in GitHub Desktop.
Save CosminLazar/d3cfe254cd203c66fdb5 to your computer and use it in GitHub Desktop.
Examples for
private void ExecutingOnANewThread()
{
//both tasks defined bellow will be executed on a new background thread
var task = new Task(() => { }, TaskCreationOptions.LongRunning);
task.Start(TaskScheduler.Default);
//or
var task2 = Task.Factory.StartNew(() => { }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
private void InstantiateAndStart()
{
var task = new Task(() => { });
task.Start(); //will use TaskScheduler.Current to schedule the task for execution
}
private void UsingTaskRun()
{
Task.Run(() => { });//will use TaskScheduler.Default to schedule the task for execution
}
private void UsingTheTaskFactory()
{
Task.Factory.StartNew(() => { }); //will use TaskScheduler.Current to schedule the task for execution
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment