๐Ÿ™‡โ€โ™€๏ธ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์˜ ์˜ˆ์‹œ๋กœ ๊ณต๋ถ€

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ: