C# await

await function holds a task till it finished, and run other codes first. This function is availabe only after .NET 4.5.

using System.Threading.Tasks;
static async Task f()
{
...
Task<string> str = f2();
return await str;
return null;
}
public async Task<string> f2()
{
...
return "";
}
In f(), if the f2 finished, then return str, otherwise return null, and the caller method of f() can be executed.

endmemo.com © 2024  | Terms of Use | Privacy | Home