WP7 BackgroundWorker线程
private BackgroundWorker _bw_1;
private BackgroundWorker _bw_2;
public Page2()
{
InitializeComponent();
_bw_1 = new BackgroundWorker();
_bw_1.DoWork+=new DoWorkEventHandler(_bw_1_DoWork);
_bw_1.ProgressChanged+=new ProgressChangedEventHandler(_bw_1_ProgressChanged);
_bw_1.RunWorkerCompleted+=new RunWorkerCompletedEventHandler(_bw_1_RunWorkerCompleted);
_bw_1.WorkerReportsProgress = true;
_bw_1.RunWorkerAsync();
_bw_2 = new BackgroundWorker();
_bw_2.DoWork += new DoWorkEventHandler(_bw_2_DoWork);
_bw_2.ProgressChanged += new ProgressChangedEventHandler(_bw_2_ProgressChanged);
_bw_2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_bw_2_RunWorkerCompleted);
_bw_2.WorkerReportsProgress = true;
_bw_2.RunWorkerAsync();
textBlock1.Text = "textBlock1显示内容";
}
private void _bw_1_DoWork(object sender,DoWorkEventArgs e)
{
BackgroundWorker _bw = sender as BackgroundWorker;
Debug.WriteLine("_bw_1 backgroundworker start..");
for (int i = 0; i < 5; i++)
{
Thread.Sleep(2000);
Debug.WriteLine("_bw_1 thread(2000)");
_bw.ReportProgress(i);
}
}
private void _bw_1_ProgressChanged(object sender,ProgressChangedEventArgs e)
{
Debug.WriteLine("_bw_1 backgroundworker ProgressChanged..");
}
private void _bw_1_RunWorkerCompleted(object sender,RunWorkerCompletedEventArgs e)
{
Debug.WriteLine("_bw_1 backgroundworker RunWorkerCompleted..");
}
private void _bw_2_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker _bw = sender as BackgroundWorker;
Debug.WriteLine("_bw_2 backgroundworker start..");
for (int i = 0; i < 5; i++)
{
Thread.Sleep(2000);
Debug.WriteLine("_bw_2 thread(2000)");
_bw.ReportProgress(i);
}
}
private void _bw_2_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Debug.WriteLine("_bw_2 backgroundworker ProgressChanged..");
}
private void _bw_2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Debug.WriteLine("_bw_1 backgroundworker RunWorkerCompleted..");
}