13 Haz

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
            }));
            threadWithoutParameter.Start();

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

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir


7 × bir =