Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All.

I have method called createrequest that accepts string parameter.
I want to create 20 thread at the same time for to start this method but method should take different parameters in every calling. It's little bit complex for me, could anyone help me?

I'm using .NET framework 3.5 and writing code in C#.
Posted
Updated 10-Jan-10 2:39am
v2

1 solution

You can use the ParameterizedThreadStart delegate overload:

C#
class Parameters
{
  public int Id { get; set; }

  // ...
}

void Start()
{
  for ( int i = 0 ; i < 20 ; i++ )
  {
    new Thread( ThreadMain ).Start( new Parameters { Id = i } );
  }
}

void ThreadMain( object state )
{
  Parameters parameters = ( Parameters ) state;

  // ...
}


Nick
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900