Interview answers verified by specialists.

Find interview questions and answers on this website:


See right interview answers on 30 common job interview questions

How do I spawn a thread?

We need to create an instance of a System.Threading.Thread object and passing it an instance of a ThreadStart delegate that will be executed on the new thread.

For example: 

class MyDemoThread 
{ 
public MyDemoThread( string initData ) 
{ 
m_data = initData; 
m_thread = new Thread( new ThreadStart(ThreadMain) ); 
m_thread.Start(); 
} // ThreadMain() is executed on the new thread. 
private void ThreadMain() 
{ 
Console.WriteLine( m_data ); 
} 
public void WaitUntilFinished() 
{ 
m_thread.Join(); 
private Thread m_thread; 
private string m_data; 
}
In this case creating an instance of the MyDemoThread class is sufficient to spawn the thread and execute the MyDemoThread.ThreadMain() method: 
MyDemoThread t = new MyDemoThread( "Hello, world." ); 
t.WaitUntilFinished();

Do you know that?

34% of freelancers earn $70 or more per hour—a comfortable range by all measures. Next

Articles:

Getting payments for Freelancers
1. Read how to register and get earned money

2. Open account within 5 minPayoneer sing up to get free $25