异步测试

 1   List< long> list = new List<long>();
 2             List<Task> tList = new List<Task>();
 3             tList.Add(Task.Factory.StartNew(() =>
 4             {
 5                 for (int i = 0; i < 100; i++)
 6                 {
 7                     list.Add(Snowflake.Instance().GetId());
 8                 }
 9             })); tList.Add(Task.Factory.StartNew(() =>
10             {
11                 for (int i = 0; i < 100; i++)
12                 {
13                     list.Add(Snowflake.Instance().GetId());
14                 }
15             }));
16 
17             Task.WaitAll(tList.ToArray());
18             list.ForEach(p => Console.WriteLine(p));

 

posted @ 2018-08-03 11:11  个人天使  阅读(228)  评论(0编辑  收藏  举报