// Sample 3: Async Task, simple version
// Starts and wait for the Task, get the result.
string result = await Read();
Console.WriteLine("Result: " + result);
// A Async Funktion thats return a Task<String>
static async Task<string> Read()
{
string rv = "";
Task task = new Task(ReadTask);
task.Start();
// Wait for finish
await task;
return rv; // Convertet to Task<string>
// Without Return-Value, is an Action<>
void ReadTask()
{
while (!System.IO.File.Exists("G:FILE")) System.Threading.Thread.Sleep(100);
rv = System.IO.File.ReadAllText("G:FILE");
}
}