IT. Expert System.

C#

async


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()
{
    // . . . .
}


Example:

using System;
using System.IO;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
	// Create task and start it.
	// ... Wait for it to complete.
	Task task = new Task(ProcessDataAsync);
	task.Start();
	task.Wait();
	Console.ReadLine();
    }

   static async Task HandleFileAsync(string file)
    {
	Console.WriteLine("HandleFile enter");
	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)
		{
		    count--;
		}
	    }
	}
	console.writeline("handlefile exit");
	return count;
    }
}

output: initial

handlefile enter
please wait patiently while i do something important.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
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 с