task一個任務結束后執行另一個操作


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM