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
);
}
}
}
}
查看全文
相关阅读:
在JavaWeb中使用Log4j步骤
关于我为什么不再更新博客园了
windows termial 配置文件
windows10 命令行修复系统引导
vscode修改code runner插件默认使用的编译器
windows下vscode修复c++找不到头文件
windows下安装mingw-w64
vscode美化方法以及定制主题插件
windows下隐藏磁盘分区
2018 icpc 徐州网络赛 F Features Track
原文地址:https://www.cnblogs.com/cl1024cl/p/6204947.html
最新文章
iOS 摇一摇事件
WeChat API Documentation
OC学习Day1
Swift学习Day007
Swift学习Day006
Swift学习Day005
mysql常用命令
通过分析java heap dump解决生产问题
堆栈分析命令
分布式部署重复提交问题
热门文章
jenkins构建启动失败
mysql 存储过程
mybatis批量更新报错
tmod命令
tomcat远程debug端口开启
分页代码核心
Java中比较不同的MD5计算方式
Problem with "AnyConnect was not able to establish connection to the specified secure gateway."
django默认开事务的麻烦事
LogBack sl4j 通过MDC实现日志记录区分用户Session[以Spring mvc为例]
Copyright © 2011-2022 走看看