KO CSharp Keyword async - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
ํธ์ถ ๊ฐ๋ฅ ๋ฉค๋ฒ์์ ๋๊ธฐ๋ฅผ ํ์ฑํํฉ๋๋ค. ์ด ๋ฉ์๋๋ Task, Task, ValueTask ๋๋ ๋น๋๊ธฐ ์ํ์ค๋ฅผ ๋ฐํํ ์ ์์ต๋๋ค. ๋น๋๊ธฐ ์์ฒด๋ ๋ณ๋์ ์ค๋ ๋๋ฅผ ์์ํ์ง ์์ต๋๋ค.
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
async System.Threading.Tasks.Task<int> ReadAsync()
{
await System.Threading.Tasks.Task.Delay(1);
return 7;
}
System.Console.WriteLine(await ReadAsync());๊ฒฐ๊ณผ:
7
async Task MethodAsync() { await ...; }using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
int result = await Jobs.DoubleAsync(4);
Console.WriteLine(result);
}
}
public static class Jobs { public static async Task<int> DoubleAsync(int value) { await Task.Delay(1); return value * 2; } }using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Task<int>[] jobs = [Jobs.CountAsync(2), Jobs.CountAsync(3)];
int[] results = await Task.WhenAll(jobs);
Console.WriteLine(results.Sum());
}
}
public static class Jobs { public static async Task<int> CountAsync(int value) { await Task.Yield(); return value; } }๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.