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
);
}
}
}
查看全文
相关阅读:
重启服务器后,托盘自启动
【转】微服务(概念篇):什么是微服务?一篇文章让你彻底搞明白
发送Http请求调用webService
sqlserver查询数据库中有多少个表,多少视图,多少存储过程,或其他对象
CDATA嵌套问题
Mysql字符串字段判断是否包含某个字符串的3种方法[转载]
处理jQuery选择器中的特殊符号,如(、#等
js数组合并(一个数组添加到另一个数组里面)方法
spring boot web项目在IDEA下热部署解决办法(四步搞定)
javascript对数组分页
原文地址:https://www.cnblogs.com/xsmhero/p/2693747.html
最新文章
linux安装 uwsgi 测试 test.py 不显示hello world 的解决办法
单选 textarea 赋初值
layui 上传图片 实现过程
layui 动画 实现过程
闭包浅析
git第一次上传push失败解决
openpyxl,xlrd,win32com,wxpython,logging
dataX的安装
【dataX】阿里开源ETL工具——dataX简单上手
用anaconda保证64位和32位的python共存
热门文章
【python3】文件格式转换windows转为unix
Python3-ibm_db模块-数据库操作之DB2
windows下 pip下载包到指定目录
windows下python虚拟环境virtualenv安装和使用
Python离线环境
计算机视觉入门和进阶学习
TFS如何强制撤销别人的机器签出的文件
C# 使用 HttpPost 请求调用 WebService
[C#]LinQ,拉姆达直接操作DataTable数据集,根据特定列进行汇总
【转】.NET(C#)有哪些主流的ORM框架,SqlSugar,Dapper,EF还是...
Copyright © 2011-2022 走看看