WPF多線程(后台線程_和異步執行)


BackgroundWorker BarckgroundworkerBtn;
private void button1_Click(object sender, RoutedEventArgs e)
{
BarckgroundworkerBtn = new BackgroundWorker();
BarckgroundworkerBtn.DoWork += new DoWorkEventHandler(BarckgroundworkerBtn_DoWork);
BarckgroundworkerBtn.RunWorkerAsync();

}
private void BarckgroundworkerBtn_DoWork(object sender, DoWorkEventArgs e)
{
Start();
}

 

、、、異步執行

//異步開始執行
Func<string> func = new Func<string>(() =>
{
this.Dispatcher.Invoke(new Action(() =>
{
for (int d = 0; d < 10; d++)
{
d++;
Thread.Sleep(1000);
progressBar1.Value = d;
}
}));
return "";
});
//異步完成時調用的方法
AsyncCallback callback = new AsyncCallback((i) =>
{
this.Dispatcher.Invoke(new Action(() =>
{
label1.Content = "異步執行完成1!";
}));
});


免責聲明!

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



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