国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

WinForm中BackgroundWorker控件用法簡單實例

2020-01-24 01:31:17
字體:
來源:轉載
供稿:網友

本文實例講述了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, "進度:" + e.ProgressPercentage.ToString());   //progressBar.Value = e.ProgressPercentage;  }  void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)  {   ThreadInvoke.SetMethodInvokeValue(label3, "結果:completed");  }  void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)  {   ThreadInvoke.SetMethodInvokeValue(label3, "結果: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();  } }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富顺县| 通榆县| 芜湖市| 来凤县| 宁都县| 天门市| 太保市| 洛隆县| 双峰县| 乐昌市| 南投市| 通道| 汉寿县| 文水县| 台安县| 轮台县| 威海市| 新密市| 加查县| 西平县| 叶城县| 金华市| 芜湖市| 邳州市| 综艺| 班玛县| 商丘市| 历史| 游戏| 泽州县| 且末县| 古丈县| 白玉县| 六盘水市| 伊春市| 犍为县| 名山县| 崇文区| 石门县| 宁明县| 大足县|