惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
博客园 - Franky
MyScale Blog
MyScale Blog
L
LangChain Blog
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
Stack Overflow Blog
Stack Overflow Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
量子位
A
About on SuperTechFans
C
Check Point Blog
大猫的无限游戏
大猫的无限游戏
Last Week in AI
Last Week in AI
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
V
Visual Studio Blog
Vercel News
Vercel News
B
Blog
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
U
Unit 42

博客园 - jueban's space

js - jueban's space - 博客园 确定删除 - jueban's space - 博客园 SQL语句大全 上海 招聘 asp.net jq 的程序员 上海 招聘 asp.net jq 程序员 sql2005 asp.net2.0安全性(1)--用户角色篇(类) 常用编码工具类,支持base64,md5,des,crc32 reg 新城管如何变老城管 xss tt 可拖动,ModalPopup 新封装的仿kijiji的城市菜单 用ajax.net封装的不间断marquee行为 http://shanghai.myol.cn/ favicon.ico图标在线制作+ico下载 验证码 转贴 lightbox
进度条
jueban's space · 2008-05-22 · via 博客园 - jueban's space

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
    
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;
            }
        }

    }

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);
            }
            MessageBox.Show(
"ok");
        }
    }

}