Winform progress bar

Source: Internet
Author: User
Using System. Threading; // Introduce namespace
Thread thread =   Null ; // Second, declare a thread object
Public   Delegate   Void Delsetpro ( Int Pros ); // Declare a delegate object

/// / <Summary>
/// Set progress bar content
///   </Summary>
///   <Param name = "pros"> Gradient value </Param>
Private   Void Setprocontent ( Int Pros)
{
If (Pros <=   100 )
{
// At first, the call is located in a thread other than the thread where the control is created. Therefore, the invoke method must be called.
If ( This . Invokerequired)
{
Delsetpro =   New Delsetpro (setprocontent );
// On the thread that owns the control, run the specified delegate with the specified parameter list
This . Invoke (delsetpro, New   Object [] {Pros });
}
Else
{
This . Pbarlinking. Value = Pros;
}
}
Else
{
Thread. Abort (); // Terminate thread
}
}

/// // <Summary>
/// Block current thread
///   </Summary>
Private   Void Sleepthread ()
{
For ( Int I =   0 ; I <   500 ; I ++ )
{
Thread. Sleep ( 100 );
// Modify the progress speed of the progress bar. You can modify the number next to [/]. The smaller the number, the faster the speed.
Setprocontent ( 100   * I /   30 );
}
}

//Finally, start the thread in the form loading event or in the button clicking event.
Thread= NewThread (NewThreadstart (sleepthread ));
Thread. Start ();

Related Article

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.