Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Creating Threads

The .NET Framework allows you to 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 an overview of techniques involved in working with multiple threads, see Thread-Safe Components.

To create a new thread of execution

  1. Declare the thread.
    ' Visual Basic
    Dim myThread as System.Threading.Thread
    
    // C#
    System.Threading.Thread myThread;
    
  2. Instantiate 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 object in C#.
    ' Visual Basic
    myThread = New System.Threading.Thread(AddressOf myStartingMethod)
    
    // C#
    myThread = new System.Threading.Thread(new 
       System.Threading.ThreadStart(myStartingMethod));
    
  3. When ready, call the Thread.Start method to start the thread.
    ' Visual Basic
    myThread.Start()
    
    // C#
    myThread.Start();
    

See Also

Thread-Safe Components | Coordinating Multiple Threads of Execution | Multithreading in Components

Show:
© 2015 Microsoft