C# Rookiss Part6 ์น์๋ฒ : Async, Await
๐โโ๏ธAsync, Await
- async/await
- async ์ด๋ฆ๋ง ๋ด๋.. ๋น๋๊ธฐ ํ๋ก๊ทธ๋๋ฐ!
- ๊ฒ์์๋ฒ) ๋น๋๊ธฐ = ๋ฉํฐ์ฐ๋ ๋? -> ๊ผญ ๊ทธ๋ ์ง๋ ์์ต๋๋ค
- ์ ๋ํฐ) Coroutine = ์ผ์ข ์ ๋น๋๊ธฐ but ์ฑ๊ธ์ฐ๋ ๋
๐ชAsync, Await
class Program
{
static Task Test()
{
Console.WriteLine("start test");
Task t = Task.Delay(3000);
return t;
}
// ์์ด์ค ์๋ฉ๋ฆฌ์นด๋
ธ๋ฅผ ์ ์กฐ์ค (1๋ถ)
// ์ฃผ๋ฌธ ๋๊ธฐ
static async void TestAsync()
{
Console.WriteLine("start TestAsync");
await Task.Delay(3000); // ๋ณต์กํ ์์
(ex. DB๋ ํ์ผ ์์
)
Console.WriteLine("End TestAsync");
}
static void Main(string[] args)
{
TestAsync();
Console.WriteLine("while start");
while (true)
{
;
}
}
}
์๊ฐ์ด ๋๋ฉด async await C#์ ๊ฒ์ํด์ ms์ ์์๋ก ๊ณต๋ถ