Copy大文件或者網絡訪問的時候處理假死。 那就用多線程加個進度條(只顯示運行,沒有進度)來表示狀態運行吧。好了,廢話少說,上個例子。先看結果圖:

程序說明:
點擊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