Use the async modifier to specify that a method, lambda expression, or anonymous method is asynchronous. If you use this modifier on a method or expression, it's referred to as an async method.
If you're new to asynchronous programming or do not understand how an async method uses the await keyword to do potentially long-running work without blocking the callerâs thread, you should read the introduction in Asynchronous
The method runs synchronously until it reaches its first await expression, at which point the method is suspended until the awaited task is complete. In the meantime, control returns to the caller of the method, as the example in the next section shows.
If the method that the async keyword modifies doesn't contain an await expression or statement, the method executes synchronously. A compiler warning alerts you to any async methods that don't contain await, because that situation might indicate an error. See Compiler Warning (level 1) CS4014.
The async keyword is contextual in that it's a keyword only when it modifies a method, a lambda expression, or an anonymous method. In all other contexts, it's interpreted as an identifier.Syntax:
public async Task ExampleMethodAsync()
// . . . .
static void Main()
// Create task and start it.
// ... Wait for it to complete.
Task task = new Task(ProcessDataAsync);
static async Task HandleFileAsync(string file)
int count = 0;
// Read in the specified file.
// ... Use async StreamReader method.
using (StreamReader reader = new StreamReader(file))
string v = await reader.ReadToEndAsync();
// ... Process the file data somehow.
count += v.Length;
// ... A slow-running computation.
// Dummy code.
for (int i = 0; i < 10000; i++)
int x = v.gethashcode();
if (x == 0)
please wait patiently while i do something important.
All information of this service is derived from the free sources and is provided solely in the form of quotations.
This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 70 / 158795098. Delta: 0.00277 с