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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.