C # multi-thread parameter passing

Source: Internet
Author: User
    Class Test
{
Private Int I;
Private String S;
Public Test ( Int N1, String S1)
{
This . I = N1;
This . S = S1;
}
Public Void Withparameters ()
{
Console. writeline ( " Thread startup, parameter {0 },{ 1} " , I, S );
}
}
Class Program
{
Static Void Main ()
{
Thread th = New Thread (New Parameterizedthreadstart (withparameters )); // You can use parameterizedthreadstart to pass an object parameter. Object parameters can be converted to multiple parameters
Th. Start ( " Parameterizedthreadstart " );
Test T = New Test ( 123 , " Parameters " ); // The custom class can pass multiple parameters.
Thread Th1 = New Thread (T. withparameters );
Th1.start ();
Thread 2nd = New Thread () => withparameters ( " Lambda " )); // The Lambda anonymous method can pass multiple parameters.
Th2.start ();
Console. readkey ();
}
Static Void Withparameters ( Object OBJ)
{
String O = OBJ As String ;
If (! String . Isnullorempty (o ))
{
Console. writeline ( " Thread startup, parameter {0} " , O );
}
}
}

 

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.