How to run asynchron Operations in C#

Its import how a Task is working. There are many ways to run asynchron operations. Sometimes you also need return values from a Task or you want to cancel/stop the Task clean. For how to cancel a task please read the section for Cancellation Token. More informations you can find on MSDN. http://msdn.microsoft.com/en-us/library/dd537609%28v=vs.110%29.aspx Here you can see a codesnippet how easy it is to deal with Tasks.
1 answer

How to run asynchron Operations in C#

using System;
using System.Threading;
using System.Threading.Tasks;
This example example includes a call to the Task.Wait method to ensure that the task completes execution before the console mode application ends.

public class Example
{
public static void Main()
{
Thread.CurrentThread.Name = "Main";

// Create a task and supply a user delegate by using a lambda expression.
Task taskA = new Task( () => Console.WriteLine("Hello from taskA."));
// Start the task.
taskA.Start();

// Output a message from the calling thread.
Console.WriteLine("Hello from thread '{0}'.",
Thread.CurrentThread.Name);
taskA.Wait();
}
}
// The example displays the following output:
// Hello from thread 'Main'.
// Hello from taskA.

Taggings: