How to Create Thread in .Net?
This example explains 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.
Code:
using System.Threading; Thread thread = new Thread(new ThreadStart(ThreadFunction)); thread.Start();
Code:
public void ThreadFunction()
{
try
{
// perform any background work
}
catch (Exception ex)
{
// log errors
}
}
Comments
Post a Comment