views:

115

answers:

2

Could anyone please give a sample or any link that describes how to spawn thread where each will do different work at the same time.

Suppose I have job1 and job2. I want to run both the jobs simultaneously. I need those jobs to get executeded parallely. how can I do that ?

Thanks

+2  A: 

Threading Tutorial from MSDN!

http://msdn.microsoft.com/en-us/library/aa645740(VS.71).aspx

Mahesh Velaga
+6  A: 

Well, fundamentally it's as simple as:

ThreadStart work = NameOfMethodToCall;
Thread thread = new Thread(work);
thread.Start();
...

private void NameOfMethodToCall()
{
    // This will be executed on another thread
}

However, there are other options such as the thread pool or (in .NET 4) using Parallel Extensions.

I have a threading tutorial which is rather old, and Joe Alabahari has one too.

Jon Skeet
suppose I have job1 and job2. I want to run both the jobs simultaneously. Your example will do it sequentially. But I need those jobs to get executeded parallely. how can I do that ?
deepak
@deepak: No it won't - you start two threads, and they will run in parallel. That's the whole point of using threads.
Jon Skeet