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
);
}
}
}
}
查看全文
相关阅读:
Django shortcut functions
Android 度量单位
WPF 资源
WPF Template
python 常用库
python 元类
android中控制ListView宽度和高度
layout可以显示,程序调用就出错
请问在pulltorefreshGridView中的图片设置了大小之后怎么就不显示了呢
Activity表单传值问题
原文地址:https://www.cnblogs.com/cl1024cl/p/6204947.html
最新文章
正则
字符窜地相关方法
jq判断是为数字
js 判断输入值是否为整数
原生js实现的ul li二级联动
使用<div><ul><li>模拟<select>下拉框
轮播
获取静态分页列表
windows下 composer常见问题及处理
php正则表达式手册
热门文章
API 友好
tinkphp5.0 traits 的引入
thinkphp5.0 自动加载
给ThinkPHP5增加验证码功能
composer 的快速安装
thinkphp 5.0 命名空间
thinkphp 5.0 模块设计
Android VelocityTracker类和Scroller类
读书笔记-构建高性能Web站点
自定义类似迅雷的漂浮窗口
Copyright © 2011-2022 走看看