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
);
}
}
}
}
查看全文
相关阅读:
在awk里引用shell变量(支持正则)
python模块pyautogui
一个完整的搜索系统
信息检索笔记(9)再论文档评分
信息检索导论学习笔记(8)向量空间模型
搜索引擎查询扩展
信息检索笔记(10)Lucene文档评分机制
Lucene的分析过程
信息检索导论学习笔记(7)文档评分、词项权重计算
信息检索导论学习笔记(5)
原文地址:https://www.cnblogs.com/cl1024cl/p/6204947.html
最新文章
Vue3 笔记文档
H5内嵌微信、IOS、android查看文件
VS Code 设置Vue代码片段
Vs Code 微信小程序 神兵利器合集
Vue beforeEach 拦截判断 PC、移动端
前端使用moment.js 获取当前时间往前的时间
(转)keytool使用
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig()
母牛生母牛 用面向对象的思想实现这个算法
mvc:annotationdriven标签的解析
热门文章
idea 基于xml创建web工程(不使用maven骨架)
springmvc的基本使用
基于web.xml的web应用的启动过程
debian中文环境建立摘要
svn小技巧——处理复杂目录结构
debian squeeze下支持adsl/pppoe的方法
小议gcc与g++的不同
关于C/C++数组符号的特殊性
为debian googlechrome 安装flash
linux下处理文件名为乱码文件
Copyright © 2011-2022 走看看