///gui類///publicpartialclassForm1:Form...{publicForm1()...{InitializeComponent();}pr" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

c#中子線程控制進度條的一個簡單例子

系統 2919 0

這個問題來自社區提問,代碼保留一份用來以后回答

using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsApplication4
... {
/**/ /// <summary>
/// gui類
/// </summary>

public partial class Form1:Form
... {
public Form1()
... {
InitializeComponent();
}

private void button1_Click( object sender,EventArgse)
... {
// 用子線程工作
new System.Threading.Thread( new System.Threading.ThreadStart(StartDownload)).Start();
}

// 開始下載
public void StartDownload()
... {
Downloaderdownloader
= new Downloader();
downloader.onDownLoadProgress
+= new Downloader.dDownloadProgress(downloader_onDownLoadProgress);
downloader.Start();
}

// 同步更新ui
void downloader_onDownLoadProgress( long total, long current)
... {
if ( this .InvokeRequired)
... {
this .Invoke( new Downloader.dDownloadProgress(downloader_onDownLoadProgress), new object [] ... {total,current} );
}

else
... {
this .progressBar1.Maximum = ( int )total;
this .progressBar1.Value = ( int )current;
}

}

}


/**/ /// <summary>
/// 下載類
/// </summary>

public class Downloader
... {
// 委托
public delegate void dDownloadProgress( long total, long current);
// 事件
public event dDownloadProgressonDownLoadProgress;
// 開始模擬工作
public void Start()
... {
for ( int i = 0 ;i < 100 ;i ++ )
... {
if (onDownLoadProgress != null )
onDownLoadProgress(
100 ,i);
System.Threading.Thread.Sleep(
100 );
}

}

}

}

c#中子線程控制進度條的一個簡單例子


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 洞头县| 翼城县| 西畴县| 仁寿县| 鲁山县| 盐山县| 关岭| 湟中县| 宝坻区| 阿拉尔市| 汉沽区| 科尔| 西乌| 息烽县| 文昌市| 和田县| 沭阳县| 甘洛县| 和硕县| 广饶县| 临漳县| 静宁县| 兴文县| 北碚区| 南昌县| 莫力| 濮阳市| 长治县| 昭苏县| 安阳市| 郎溪县| 田阳县| 巴林右旗| 来安县| 辉县市| 横峰县| 图木舒克市| 寿光市| 田东县| 芜湖市| 昂仁县|