欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

WinForm中BackgroundWorker控件用法簡(jiǎn)單實(shí)例

 更新時(shí)間:2015年08月21日 09:52:00   作者:我心依舊  
這篇文章主要介紹了WinForm中BackgroundWorker控件用法,以一個(gè)簡(jiǎn)單實(shí)例形式分析了BackgroundWorker控件的定義、設(shè)置及使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了WinForm中BackgroundWorker控件用法。分享給大家供大家參考。具體如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinFormApp
{
 public partial class Form2 : Form
 {
  BackgroundWorker backgroundWorker;
  int i = 0;
  int len = 100;
  public Form2()
  {
   InitializeComponent();
   backgroundWorker = new BackgroundWorker();
   backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
   backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
   backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
   backgroundWorker.WorkerReportsProgress = true;
  }
  void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
  {
   ThreadInvoke.SetMethodInvokeValue(label2, "進(jìn)度:" + e.ProgressPercentage.ToString());
   //progressBar.Value = e.ProgressPercentage;
  }
  void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
   ThreadInvoke.SetMethodInvokeValue(label3, "結(jié)果:completed");
  }
  void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
  {
   ThreadInvoke.SetMethodInvokeValue(label3, "結(jié)果:start");
   while (i < len)
   {
    i++;
    System.Threading.Thread.Sleep(100);
    ThreadInvoke.SetMethodInvokeValue(label1, "工作:" + (i * 10).ToString());
    backgroundWorker.ReportProgress(i);
    Application.DoEvents();
   }
  }
  private void button1_Click(object sender, EventArgs e)
  {
   backgroundWorker.RunWorkerAsync();
  }
 }
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論