You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
2 years ago
|
namespace MyConsoleApp.Work
|
||
|
{
|
||
|
public class AsyncAwaitWork
|
||
|
{
|
||
|
private static Task Test()
|
||
|
{
|
||
|
System.Console.WriteLine("Start Test");
|
||
|
Task t = Task.Delay(3000);
|
||
|
return t;
|
||
|
}
|
||
|
|
||
|
private static async void TestAsync()
|
||
|
{
|
||
|
System.Console.WriteLine("Start Test");
|
||
|
Task t = Task.Delay(3000);
|
||
|
await t; // 함수 내부에서는 동기, 함수 호출부에서는 비동기로 처리됨
|
||
|
System.Console.WriteLine("End TestAsync");
|
||
|
}
|
||
|
|
||
|
private static async Task<int> TestAsync2()
|
||
|
{
|
||
|
System.Console.WriteLine("Start Test");
|
||
|
Task t = Task.Delay(3000);
|
||
|
await t;
|
||
|
System.Console.WriteLine("End TestAsync");
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
public async static void DoTest()
|
||
|
{
|
||
|
// Task t = Test();
|
||
|
// t.Wait();
|
||
|
|
||
|
//TestAsync();
|
||
|
await TestAsync2(); // 메인 함수도 동기로 처리됨
|
||
|
|
||
|
int res = await TestAsync2();
|
||
|
|
||
|
System.Console.WriteLine("While start");
|
||
|
while (true)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|