First Encounter multithreading

Source: Internet
Author: User

The first contact with multi-threading is to make a progress bar, and then let the interface have a anti-animation effect. Understand not deep, first plain record:

Private Thread Fthread; Define a process

Start process
private void Btdoit_click (object sender, EventArgs e)
{
Fthread = new Thread (new ThreadStart (Addinfo));//Specifies that the process executes a function of addinfo;
Fthread.start ();
}

private void Addinfo ()//This is the function of the process execution, not much to remember

{

。。。。。

}

Conditions encountered when using multi-threading:

1. Calling controls across threads

Add this before invoking the control, as you would call the ListView control here:

if (this.listViewfw.InvokeRequired)
{
Addinfocallback ACB = new Addinfocallback (addinfo);
This.listViewfw.Invoke (ACB, new object[] {});

}
Else
{

The action to perform

}

2, the execution of a large loop, the progress bar value can be changed, the value of lable cannot be changed in real time (this should not be related to multithreading, but encountered in the incidentally recorded)

Add this sentence before changing the value of lable or other controls:

Application.doevents ();//This sentence I checked, said that it will cause the system a short pause, the impact of speed, need to use caution.

First Encounter multithreading

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.