zoukankan
html css js c++ java
c#中子线程控制进度条的一个简单例子
这个问题来自社区提问,代码保留一份用来以后回答
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, EventArgs e)
...
{
//
用子线程工作
new
System.Threading.Thread(
new
System.Threading.ThreadStart(StartDownload)).Start();
}
//
开始下载
public
void
StartDownload()
...
{
Downloader downloader
=
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
dDownloadProgress onDownLoadProgress;
//
开始模拟工作
public
void
Start()
...
{
for
(
int
i
=
0
; i
<
100
; i
++
)
...
{
if
(onDownLoadProgress
!=
null
)
onDownLoadProgress(
100
, i);
System.Threading.Thread.Sleep(
100
);
}
}
}
}
查看全文
相关阅读:
串口基本知识
20180826
20180819
自动化测试
说话有重点 测试思维
学习C语言,在软件测试中如何用?
PC能替代服务器吗?
服务器与普通电脑的区别?
k8s 回滚应用
k8s Service
原文地址:https://www.cnblogs.com/cl1024cl/p/6204947.html
最新文章
[Java]剑指offer:找出数组中两个只出现一次的数字
[Java]剑指offer:子数组的最大累加和问题
解决安装MySQL5.5 出现Cannot create windows service for mysql.error:0
从GitHub下载慢及失败问题的解决方法
两只小熊队高级软件工程第九次作业敏捷冲刺7
两只小熊队高级软件工程第九次作业敏捷冲刺6
两只小熊队高级软件工程第九次作业敏捷冲刺5
两只小熊队高级软件工程第九次作业敏捷冲刺4
两只小熊队高级软件工程第九次作业敏捷冲刺3
两只小熊队高级软件工程第九次作业敏捷冲刺2
热门文章
两只小熊队高级软件工程第九次作业敏捷冲刺1
Alpha阶段个人总结
两只小熊队高级软件工程第七次作业敏捷冲刺7
两只小熊队高级软件工程第七次作业敏捷冲刺6
字符驱动之按键(四:poll机制)
字符驱动之按键(一:无脑轮询法)
字符驱动之LED(三:改进测试程序)
字符驱动之LED(二:实现点灯功能)
字符驱动之操作LED灯(一):大体框架
内存知识
Copyright © 2011-2022 走看看