资源简介
C#使用委托和事件写的,一个多线程进度条的Demo。
代码片段和文件信息
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;
using System.Threading;
namespace MultiThreadProcess_Test
{
public partial class Form1 : Form
{
protected Thread thread1 = null;//开启新的线程(用来处理数据)
public static bool isStop = false;//控制线程的暂停和继续的标记
public AutoResetEvent autoResetEvent = new AutoResetEvent(false);//控制线程的暂停和继续
private delegate void MessageEventHandler(object sender ProgressBarValueEventArgs e);
private event MessageEventHandler messageEvent;
private delegate void RefreshButtonEventHandler();
private event RefreshButtonEventHandler refreshButtonEvent;
public Form1()
{
InitializeComponent();
messageEvent += new MessageEventHandler(PassInfo);//第一种方式
//messageEvent += new MessageEventHandler(ShowProcessing);//第二种方式(同刷新按钮)
refreshButtonEvent += new RefreshButtonEventHandler(RefreshButton);
btnStart.Enabled = true;
btnStop.Enabled = false;
btnContinue.Enabled = false;
btnOver.Enabled = false;
}
public void Thread_DataProcessing()
{
ProgressBarValueEventArgs progressbarValueEventArgs = new ProgressBarValueEventArgs(0 “开始处理...“);
ShowProcessing(this progressbarValueEventArgs);//进度提示
int intCount = 100;
for (int i = 0; i < intCount; i++)//这个循环可以换成处理自己的数据
{
progressbarValueEventArgs = new ProgressBarValueEventArgs((int)((i + 1) * 100 / intCount) string.Format(“已处理{0}/{1}个数据“ (i + 1) intCount));
ShowProcessing(this progressbarValueEventArgs);
System.Threading.Thread.Sleep(50);
if (isStop)
autoResetEvent.WaitOne();//线程暂停
}
progressbarValueEventArgs = new ProgressBarValueEventArgs(100 “数据处理已完成“);
ShowProcessing(this progressbarValueEventArgs);
refreshButtonEvent();//刷新按钮
}
public void ShowProcessing(object sender ProgressBarValueEventArgs e)
{
this.Invoke(this.messageEvent new object[] { sender e });
//this.BeginInvoke(this.messageDelegate new object[] { sender e });
//if (this.InvokeRequired)
//{
// this.Invoke(this.messageEvent new object[] { sender e });
//}
//else
//{
// this.lblProgressInfo.Text = string.Format(“{0} {1}%“ e.DescriptionStr e.Process);
// this.progressBar1.Value = e.Process;
//}
}
private void PassInfo(object sender ProgressBarValueEventArgs e)
{
if (thread1 == null)
{
this.
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 911 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test.sln
..A..H. 22016 2016-09-18 09:45 MultiThreadProcess_Test\MultiThreadProcess_Test.suo
文件 6579 2016-09-18 09:43 MultiThreadProcess_Test\MultiThreadProcess_Test\Form1.cs
文件 5236 2016-09-18 09:28 MultiThreadProcess_Test\MultiThreadProcess_Test\Form1.Designer.cs
文件 5817 2016-09-14 09:33 MultiThreadProcess_Test\MultiThreadProcess_Test\Form1.resx
文件 3761 2016-09-18 09:20 MultiThreadProcess_Test\MultiThreadProcess_Test\MultiThreadProcess_Test.csproj
文件 504 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\Program.cs
文件 680 2016-09-18 09:21 MultiThreadProcess_Test\MultiThreadProcess_Test\ProgressBarValueEventArgs.cs
文件 12800 2016-09-18 09:43 MultiThreadProcess_Test\MultiThreadProcess_Test\bin\Debug\MultiThreadProcess_Test.exe
文件 26112 2016-09-18 09:43 MultiThreadProcess_Test\MultiThreadProcess_Test\bin\Debug\MultiThreadProcess_Test.pdb
文件 11600 2016-09-18 16:25 MultiThreadProcess_Test\MultiThreadProcess_Test\bin\Debug\MultiThreadProcess_Test.vshost.exe
文件 2855 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6407 2016-09-18 09:43 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 1051 2016-09-18 16:25 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\MultiThreadProcess_Test.csproj.FileListAbsolute.txt
文件 975 2016-09-18 09:30 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\MultiThreadProcess_Test.csproj.GenerateResource.Cache
文件 12800 2016-09-18 09:43 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\MultiThreadProcess_Test.exe
文件 180 2016-09-18 09:30 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\MultiThreadProcess_Test.Form1.resources
文件 26112 2016-09-18 09:43 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\MultiThreadProcess_Test.pdb
文件 180 2016-09-18 09:30 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\MultiThreadProcess_Test.Properties.Resources.resources
文件 1378 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\Properties\AssemblyInfo.cs
文件 2898 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\Properties\Resources.Designer.cs
文件 5612 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\Properties\Resources.resx
文件 1110 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\Properties\Settings.Designer.cs
文件 249 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\Properties\Settings.settings
目录 0 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug\TempPE
目录 0 2016-09-18 09:43 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86\Debug
目录 0 2016-09-18 09:30 MultiThreadProcess_Test\MultiThreadProcess_Test\bin\Debug
目录 0 2016-09-18 09:18 MultiThreadProcess_Test\MultiThreadProcess_Test\bin\Release
目录 0 2016-09-18 09:14 MultiThreadProcess_Test\MultiThreadProcess_Test\obj\x86
目录 0 2016-09-18 09:18 MultiThreadProcess_Test\MultiThreadProcess_Test\bin
............此处省略7个文件信息
相关资源
- c# 解压zip完整demo 带进度条
- 带进度条的C#软件启动特效,类似Wo
- C# Http协议上传文件有进度条
- C#CircularProgressBar
- ASP.net AJAX进度条批量插入大量数据
- wpf进度条,wpf等待条,wpf loading
- 在Winform中实现带进度条的DataGridView控
- C#+WinForm+经过美化的进度条控件
- ASP.NET实现EXCEL数据导入进度条ajax
- C#winform实现模态加载进度条.rar.rar
- C# Winform垂直进度条控件附源码
- 控制台 ProgressBar进度条
- html5简单进度条效(progressbar)
- 根据文件大小显示文件复制进度条
- 弹出模式窗口显示进度条
- Progressbar进度条控件
- wpf自定义进度条
- 文件传输,大文件分包传输,含进度
- C# ASP.NET 图片批量上传,可预览带进度
- trackBar进度条的颜色及样式均可以修改
- asp.net单文件带进度条上传
- C# 仿酷狗播放器进度条(和演示)。
- C# 实现进度条 倒着进度 以及竖着进度
- C# winForm漂亮进度条控件(带百分比)
- wcf 实现大文件上传(有进度条)
- C# 断点续传文件带进度条源码
- 基于MATLAB混合编程图像分析及数据处
- C# GDI+绘制圆形进度条制作自定义控件
- WPF实现的圆形进度条
- C# 自定义ProgressBar 进度条控件
评论
共有 条评论