- Create a new console application in Visual Studio.
- Next, add a class called Demo to your console application.
- Inside the Demo class, add a method called DoBackgroundTask() with the public void modifiers, and add the following console output to it:
public void DoBackgroundTask() { WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId} has a threadstate of {Thread.CurrentThread.ThreadState} with {Thread.CurrentThread.Priority} priority"); WriteLine($"Start thread sleep at {DateTime.Now.Second} seconds"); Thread.Sleep(3000); WriteLine($"End thread sleep at {DateTime.Now.Second} seconds"); }
Make sure that you have added the using statements for System.Threading and static System.Console to your using statements.