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
);
}
}
}
}
查看全文
相关阅读:
设计模式のIteratorPattern(迭代器模式)----行为模式
设计模式のChainOfResponsibilityPattern(责任链模式)----行为模式
设计模式のProxyPattern(代理模式)----结构模式
设计模式のFlyweight(享元模式)----结构模式
设计模式のFacadePattern(外观模式)----结构模式
js代码判断浏览器种类IE、FF、Opera、Safari、chrome及版本
实现图片预加载
移动端 下滑时加载新数据
各种高度
js验证input输入正整数 和 输入的金额小数点后保留两位(PC端键盘输入)
原文地址:https://www.cnblogs.com/cl1024cl/p/6204947.html
最新文章
SpringBlade 功能模块 字段为字典类型 下拉项为字典值
SpringBlade bug mybatisplus 生成代码前判断一下表是否存在
SQL Server 字符串截取
PowerDesigner table视图 显示name
AVUE bug 树型下拉框 编辑时 没有默认选中
AVUE crud 里面的 form表单 的保存事件
观察者(observer)设计模式
多次绑定DataGridView的DataSource会报错 NullReferenceExcepti
T-SQL语句
C#中如何将combox中的下拉项和一个枚举中的各项进行绑定
热门文章
Web Service 中返回DataSet
WinForm DataGridView分页功能
SqlBulkCopy批量复制
datagridview添加复选框全选和取消
winfrom datagridview分页显示
winfrom动态生成控件
设计模式のNullObjectPattern(空对象模式)----行为模式
设计模式のStatePattern(状态模式)----行为模式
设计模式のMementoPattern(备忘录模式)----行为模式
设计模式のMediatorPattern(中介者模式)----行为模式
Copyright © 2011-2022 走看看