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);