Windows Form (C #) Progress bar Processing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.