Create New Thread [C#]

By Kelvin
Nov 07, 2018 512

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. Pass this delegate as a parameter when creating a new Thread instance. Finally, call the Thread.Start method to run your method (in this case WorkThreadFunction) on background.

[C#]

using System.Threading;

Thread thread = new Thread(new ThreadStart(WorkThreadFunction));
thread.Start();

The WorkThreadFunction could be defined as follows.

[C#]

public void WorkThreadFunction()
{
  try
  {
    // do any background work
  }
  catch (Exception ex)
  {
    // log errors
  }
}

Leave A Comment


{{i.FullName}}

{{i.Message}}

  • {{i.CreatedOn | jsonDate}}

RELATED VIDEOS

Youtube

Video's Name

Video's Name

By Kelvin
25/3/2015 1,200
Youtube

Video's Name

Video's Name

By Kelvin
25/3/2015 1,200
Youtube

Video's Name

Video's Name

By Kelvin
25/3/2015 1,200