質問編集履歴
1
説明の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
|
1
|
+
t1も、t2も同じタスクですが、t2は処理が止まったままConsole.WriteLine("goal");まで到達できません。
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
どちらも同じTaskですが、
|
6
|
-
|
7
|
-
|
3
|
+
t1と、t2では何が違うのでしょうか?
|
8
4
|
|
9
5
|
|
10
6
|
|
@@ -20,28 +16,32 @@
|
|
20
16
|
|
21
17
|
class Program {
|
22
18
|
|
23
|
-
static
|
19
|
+
static void Main(string[] args) {
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
Async();
|
28
|
-
|
29
|
-
Task t2 = new Task( () => Thread.Sleep(1000));
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
await t1; //OK
|
34
|
-
|
35
|
-
//await t2; //NG
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
Console.WriteLine("main");
|
40
22
|
|
41
23
|
Console.Read();
|
42
24
|
|
43
25
|
}
|
44
26
|
|
27
|
+
static async Task Async() {
|
28
|
+
|
29
|
+
Task t1 = Task.Delay( 999);
|
30
|
+
|
31
|
+
Task t2 = new Task(() => Thread.Sleep( 999));
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
await t1; //OK
|
36
|
+
|
37
|
+
await t2; //NG
|
38
|
+
|
39
|
+
Console.WriteLine("goal");
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
45
|
}
|
46
46
|
|
47
47
|
```
|