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
);
}
}
}
}
查看全文
相关阅读:
Python学习笔记(尚硅谷)——变量
四级高频词-工作类
转载--JS根据浏览器的useAgent来判断浏览器的类型
MySQL上传文件容量过大com.mysql.jdbc.PacketTooBigException
关于<input type="file" >浏览器兼容问题
IDictionary与TryGetValue
生成自增ID列
利用C#将PCM格式的Wav进行对文件裁剪截取、淡入淡出、保存为音频文件相关详细代码解释
DevExpress控件学习总结
C# 音频操作系统项目总结
原文地址:https://www.cnblogs.com/cl1024cl/p/6204947.html
最新文章
JVM
Mybatis SqlsessionFactory
Mybatis 接口代理的实现(BeanDefinitionRegistryPostProcessor+FactoryBean)
jdk1.8 HashMap的实现
Spring基础-BeanPostProcessor
Spring基础-如何获取ApplicationContext
Spring基础
http升级为https
Redis zset
redis set操作
热门文章
Redis list 操作
redis hash操作
redis 字符串基本操作
LeetCode-返回倒数第 k 个节点
概率论-随机事件及其概率
HTML表单input里面的value的作用
JavaWeb项目中解决中文乱码方法
MATLAB基础知识
Mysql基础笔记
try-catch-finally机制
Copyright © 2011-2022 走看看