How to do it...

  1. Create a new console application in Visual Studio.
  1. Next, add a class called Demo to your console application.
  1. 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.

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.