1 //创建一个任务 2 Task<int> task = new Task<int>(() => 3 { 4 int sum = 0; 5 //显示进度条遮照层, 6 this.ShowPrograssBar(); 7 this.InitChartXml(); 8 return sum; 9 }); 10 //启动任务,并安排到当前任务队列线程中执行任务(System.Threading.Tasks.TaskScheduler) 11 task.Start(); 12 13 14 //任务完成时执行处理。 15 Task cwt = task.ContinueWith(t => 16 { 17 this.Dispatcher.BeginInvoke(new Action(() => 18 { 19 20 })); 21 this.HiddenPrograssBar(); 22 // 取消遮照层 23 // Console.WriteLine("任务完成后的执行结果:{0}", t.Result.ToString()); 24 }); 25 Thread.Sleep(100);