problem: processing a large amount of data in the background, the main interface does not die, the progress bar is displayed, and the main program body continues to run after the data processing has finished.
1 {2 //Main Program 13 }4 //inserting code5Thread T1 =NewThread (startwork);6T1. IsBackground =true;7 t1. Start ();8Finishhandler=9 Delegate(){Ten //Main program 2 One //There may be an error: The call was not created by this thread ... BlaBla A //Use this. Invoke (related code delegate); - } - the///////////////////////////////////////////////// - //delegate-related - Private Delegate voidPromanager (); - Private Delegate voidonfinished (); + Privateonfinished Finishhandler; - + Private voidstartdb3work (Object o) A { atPromanager ProStart =NewPromanager (Startpro); - progress. Invoke (ProStart); - 26 {
- //Data processing code - } in if(finishhandler!=NULL) - Finishhandler (); to } + - //ProgressBar Related Codes the System.Windows.Forms.Timer Timer; * Private voidStartpro () $ {Panax NotoginsengProgress. Minimum =0; -Progress. Maximum = -; theProgress. Value =0; + ATimer =NewSystem.Windows.Forms.Timer (); theTimer. Tick + =NewEventHandler (Tpro_tick); + timer. Start (); - } $ Private voidTpro_tick (ObjectSender,eventargs e) $ { - intINum =progress. Value; - if(INum! = -) the { -Progress. Increment (4);Wuyi } the Else - { WuProgress. Value =0; - } About } $ Private voidClosepro () - { - if(timer!=NULL) - { A timer. Stop (); + timer. Dispose (); theTimer =NULL; - } $Progress. Value = -; the}
Windows Form (C #) Progress bar Processing