C # Multithreading

Source: Internet
Author: User

Multithreading:

Thread t = new Thread (new ThreadStart (StartMethod); t. start (); private void StartMethod () {Thread. sleep (5000); MessageBox. show ("c ");}

The multi-thread function is the same as the asynchronous call function. It is used to continue the remaining statements after the called function is run.

ParameterizedThreadStart is a parameter-oriented method. The parameter type is object. StartMethod () is a method without parameters. StartMethod (object I) is a method with parameters. Everyone knows this ~

T. IsBackground = true;

This code means that when the main program is finished, if the code of the supporting thread is not finished, I am sorry ..

At this time, people don't want to talk to the world so early...

Just add t. Join (); at the end of the main program ~.

Why use this. what about invoke? It seems that it is no different from calling a function directly. But if you want to assign a value to the control in the function of the supporting thread, the code will report an error. At this time, this. invoke, this. begininvoke can be used, so that no error is reported.

 

Public void DoWork () {MyInvoke mi = new MyInvoke (Updatetxt); this. beginInvoke (mi, new Object [] {""});} public void Updatetxt (string param) {textBox1.Text = param ;}

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.