0 out of 2 rated this helpful - Rate this topic

How to: Create Threads

The BackgroundWorker component replaces and adds functionality to the System.Threading namespace; however, the System.Threading namespace is retained for both backward compatibility and future use, if you choose. For more information, see BackgroundWorker Component Overview.

With the .NET Framework, you can create multithreaded applications quickly and easily by providing an object-oriented threading model. Creating a new thread is as easy as declaring it and supplying it with a delegate to the method where the thread is to start. When you are ready to begin execution on the thread, call the Thread.Start method. There are special considerations involved when working with multiple threads of execution. For information about the techniques involved in working with multiple threads, see Thread-Safe Components.

To create a new thread of execution

  1. Declare the thread.

    System.Threading.Thread myThread;
    
  2. Create an instance of the thread with the appropriate delegate for the starting point of the thread. Use the AddressOf operator to create the delegate in Visual Basic, or create a new ThreadStart in Visual C#.

    myThread = new System.Threading.Thread(new 
       System.Threading.ThreadStart(myStartingMethod));
    
  3. When ready, call the Thread.Start method to start the thread.

    myThread.Start();
    
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.