Introduction to the multi-Thread Series II: What about Thread?

Source: Internet
Author: User

1:You can call the instance method of the threadJoinTo wait for the end of a thread. For example:

Public   Static   Void MainThread ()
{
Thread t =   New Thread (Go );
T. Start ();
T. Join ();
Console. WriteLine ( " Thread t has ended! " );
}

Static   Void Go ()
{
For ( Int I =   0 ; I <   1000 ; I ++ )
Console. Write ( " Y " );
}

After printing1000ItemsYAnd then output"Thread t has ended !".,

You can callJoinMethodTimeoutFor example, to time out for one second:

T. Join ( 1000 );
T. Join (TimeSpan. FromSeconds ( 1 ));

 

2:Passing parameters for threads

The simplest way to pass parameters for a thread is to executeLambdaExpression, and then the parameter is given in the method, for example:

Static   Void Main ()
{
Thread t =   New Thread (() =>

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.