Async/Await

Posted by Leo Yang on 2020-08-24

Async、Await、Task

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
static void Main(string[] args)
{
TestService sv = new TestService();
sv.Function();
Console.WriteLine("done");
Console.Read();
}


public class TestService
{
public TestService()
{

}

public async Task Function()
{
Stopwatch st = new Stopwatch();
st.Start();
await Task.Delay(10000);
st.Stop();
Console.WriteLine(st.ElapsedMilliseconds/1000);
}
}

Task更新資料

1
2
3
4
private async void CommonFlowClickCommandAction(object obj)
{
await Task.Run(() => CommonFlow());
}