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
);
}
}
}
查看全文
相关阅读:
饿了么 PostgreSQL 优化之旅
kubernetes 滚动更新发布及回滚
kubernetes yaml
mongodb安装
node.js安装
linux输出换行
把token放入请求头
$.ajaxSetup
js前端读取文件内容
v-echarts安装
原文地址:https://www.cnblogs.com/xsmhero/p/2693747.html
最新文章
<%#Eval if判断用法
常用操作方法类
中等难度SQL语句(存储过程,分页,拼接字段、游标,日期类型转换,动态行转列,视图)汇总
Codeforces Round #426 (Div. 2) D 线段树优化dp
Codeforces Round #427 (Div. 2) D dp
玲珑学院oj 1152 概率dp
Codeforces Round #271 (Div. 2) E. Pillars 线段树优化dp
Codeforces Round #305 (Div. 2) D 维护单调栈
HDU 3480 斜率dp
玲珑杯”ACM比赛 Round #19 B 维护单调栈
热门文章
2017 Multi-University Training Contest
Codeforces Round #271 (Div. 2) D 简单dp
2017 Multi-University Training Contest
Gluster 常用命令
Web 协议 HTTP1.0 HTTP1.1 SPDY HTTP2.0
GlusterFS 三
GlusteFS 二
GlusterFS 一
linux 流量统计
ubuntu16.04 安装jdk 错误解决
Copyright © 2011-2022 走看看