Last active
August 29, 2015 14:01
-
-
Save CosminLazar/d3cfe254cd203c66fdb5 to your computer and use it in GitHub Desktop.
Examples for
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
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); | |
} |
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
private void InstantiateAndStart() | |
{ | |
var task = new Task(() => { }); | |
task.Start(); //will use TaskScheduler.Current to schedule the task for execution | |
} |
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
private void UsingTaskRun() | |
{ | |
Task.Run(() => { });//will use TaskScheduler.Default to schedule the task for execution | |
} |
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
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