13 Jun

C# Create A New Thread With/Without Parameter

This example shows how to create a new thread in .NET Framework.
First, create a new ThreadStart delegate.
The delegate points to a method that will be executed by the new thread.
Then, call Start method. If you want to pass a parameter to the thread,

Sample Code:

            //start without parameters
            Thread threadWithoutParameter = new Thread(new ThreadStart(delegate()
                //do anything on background

            //start with parameters
            Thread threadWithParameter = new Thread(new ParameterizedThreadStart(delegate(object obj)
                //do anything on background
            object param = "Thread parameter";

Leave a Reply

Your email address will not be published. Required fields are marked *