O'Reilly logo

C# 7 and .NET Core Cookbook by Dirk Strauss

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required