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
);
}
}
}
}
查看全文
相关阅读:
利用自定义分页技术提高数据库性能
solr深分页,游标操作分页,解决性能问题
Selenium2+python自动化54-unittest生成测试报告(HTMLTestRunner)
Selenium2+python自动化53-unittest批量执行(discover)
Selenium2+python自动化52-unittest执行顺序
Selenium2+python自动化51-unittest简介
Fiddler抓包2-只抓APP的请求
selenium3+python自动化50-环境搭建(firefox)
Selenium2+python自动化49-判断文本(text_to_be_present_in_element)
Selenium2+python自动化47-判断弹出框存在(alert_is_present)
原文地址:https://www.cnblogs.com/cl1024cl/p/6204947.html
最新文章
建立你数据分析的思维框架
一个常见大数据平台架构
大数据价值变现的10种商业模式
awk如何区分shell脚本传进来的参数和自身的参数?awk如何获取shell脚本传进来的参数;awk中如何执行shell命令
linux删除空行操作:awk、grep、tr、sed
如何使用ssh远程编辑定时任务crontab?
awk的求和计算使用;awk多个分隔符如何使用?
jenkins执行单元测试,会产生大量临时文件,要及时删除,不然会把inode耗尽
为什么硬盘明明还有空间,linux却说硬盘空间不足?inode;mkdir: 无法创建目录"shen1": 设备上没有空间
如何模拟alert/confirm/prompt实现阻断程序运行
热门文章
jquery的ajax用法
mysql数据库连接状态,不要做修改数据库表结构的操作;数据库迁移操作;
SSH错误:packet_write_wait: Connection to 10.57.19.250 port 22: Broken pipe
跨站脚本攻击XXS(Cross Site Scripting)修复方案
Acunetix Web Vulnerability Scanner使用和生成报告的方法
Apache JServ protocol服务 怎么关闭?
MySQL详解(25)-----------MySQL性能优化
MySQL性能优化必备25条
MySQL详解(18)-----------分页方法总结
分页存储过程性能比较 二分法
Copyright © 2011-2022 走看看