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