First to load a form of code
1 public partial class FrmLoading : Form 2 { 3 public BackgroundWorker updateDBWorker=new BackgroundWorker(); 4 5 public Action BackgroundWorkAction 6 { 7 get; 8 set; 9 } 10 11 public KeyValuePair<int, string> CurrentMsg 12 { 13 set 14 { 15 this.updateDBWorker.ReportProgress(value.Key, value.Value); 16 } 17 } 18 19 public FrmLoading() 20 { 21 InitializeComponent(); 22 this.updateDBWorker.WorkerReportsProgress = true; 23 this.updateDBWorker.WorkerSupportsCancellation = true; 24 this.updateDBWorker.DoWork += new DoWorkEventHandler(this.backgroundWorker1_DoWork); 25 this.updateDBWorker.ProgressChanged += new ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); 26 this.updateDBWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); 27 lblVer.Text = Properties.Resources.SystemVer; 28 } 29 30 31 public void ShowLog(string strLog, int intValue) 32 { 33 if (this.lblLog.InvokeRequired) 34 { 35 this.lblLog.BeginInvoke(new MethodInvoker(delegate() { ShowLog(strLog, intValue); })); 36 } 37 else 38 { 39 lblLog.Text = strLog; 40 this.progressBar1.Value = intValue; 41 } 42 } 43 44 private void FrmLoading_Load(object sender, EventArgs e) 45 { 46 this.updateDBWorker.RunWorkerAsync(); 47 } 48 49 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) 50 { 51 if (this.BackgroundWorkAction != null) 52 { 53 this.BackgroundWorkAction(); 54 } 55 Thread.Sleep(100); 56 if (base.InvokeRequired) 57 { 58 base.BeginInvoke(new MethodInvoker(delegate 59 { 60 base.Close(); 61 })); 62 } 63 else 64 { 65 base.Close(); 66 } 67 } 68 69 private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) 70 { 71 ShowLog((e.UserState == null) ? "" : e.UserState.ToString(), e.ProgressPercentage); 72 } 73 74 private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 75 { 76 } 77 }
A progress bar on the screen, a label, not anything else
Look calling the place, Program Files inside
. 1 FrmLoading frmLoading = new new FrmLoading (); 2 frmLoading.BackgroundWorkAction = the delegate . 3 { . 4 the try . 5 { . 6 // set the connection string . 7 frmLoading.CurrentMsg = new new KeyValuePair < int , String > ( . 1 , " Initializing configuration data .. . " ); . 8 . 9 frmLoading.CurrentMsg = new newKeyValuePair < int , String > ( . 5 , " Initializing Log Configuration ... " ); 10 System.Threading.Thread.Sleep ( 200 is ); . 11 12 is frmLoading.CurrentMsg = new new KeyValuePair < int , String > ( 10 , " is upgrade local data ... " ); 13 is 14 frmLoading.CurrentMsg = new new KeyValuePair < int , String > ( 50 ," Is initialized local parameters ... " ); 15 16 frmLoading.CurrentMsg = new new KeyValuePair < int , String > ( 85 , " Initializing hotkeys ... " ); . 17 18 is frmLoading.CurrentMsg = new new KeyValuePair < int , String > ( 90 , " initializing hardware device ... " ); . 19 20 is frmLoading.CurrentMsg = new new KeyValuePair < int ,string>(100, "初始化完成..."); 21 22 } 23 catch (Exception ex) 24 { 25 Application.Exit(); 26 Process.GetCurrentProcess().Kill(); 27 } 28 }; 29 frmLoading.ShowDialog(); 30 31 Application.Run(new form1());
Well, it is so, no technical content, not a map, you can have it