当前位置:编程学习 > C#/ASP.NET >>

C#多线程显示运行状态

Copy大文件或者网络访问的时候处理假死。 那就用多线程加个进度条(只显示运行,没有进度)来表示状态运行吧。好了,废话少说,上个例子。先看结果图:

image image

程序说明:

点击Button,运行一个数据累加器,textBox显示每次运行的结果,ProgressBar表示运行的状态。

好了,直接贴代码:

01 using System;
02 using System.Collections.Generic;
03 using System.ComponentModel;
04 using System.Data;
05 using System.Drawing;
06 using System.Linq;
07 using System.Text;
08 using System.Windows.Forms;
09 using System.Threading;
10   
11 namespace Testpro
12 {
13     public partial class Form1 : Form
14     {
15         BackgroundWorker work = new BackgroundWorker();
16         public Form1()
17         {
18             InitializeComponent();
19             work.WorkerReportsProgress = true;
20             work.DoWork += Count;
21             work.RunWorkerCompleted += completeRun;
22             Control.CheckForIllegalCrossThreadCalls = false;
23             this.textBox1.ScrollBars = ScrollBars.Both;
24         }
25   
26
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,