9

I'm working with .NET Core on my Mac machine.

Somewhere in my code I want to use this code:

System.Threading.Thread.Sleep(100);

But it can not find Thread in System.Threading namespace.

What's wrong? Isn't Thread available for Mac, or I'm missing something?

mehrandvd
  • 8,806
  • 12
  • 64
  • 111
  • 4
    Meh, don't hold your breath for it. This was dropped long before CoreFx was started. Task.Delay() is the way forward, it is the Right Way™ – Hans Passant Apr 12 '16 at 10:18

2 Answers2

12

Do you have System.Threading.Thread package added to your project.json?

{
    "version": "1.0.0-*",
    "compilationOptions": {
        "emitEntryPoint": true
    },

    "dependencies": {
        "NETStandard.Library": "1.0.0-rc2-23811",
        "System.Threading.Thread": "4.0.0-beta-23516"
    },

    "frameworks": {
        "dnxcore50": { }
    }
}

Then I can use Thread.Sleep:

using System;
using System.Threading;


    namespace ConsoleApplication
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                Console.WriteLine(DateTime.Now);
                Thread.Sleep(2000);
                Console.WriteLine("Hello World!");
                Console.WriteLine(DateTime.Now);
            }
        }
    }

enter image description here

Anton Sizikov
  • 9,105
  • 1
  • 28
  • 39
6

Isn't Thread available for Mac?

Not yet: https://github.com/dotnet/corefx/issues/2576

The current System.Threading.Thread (and System.Threading.ThreadPool) packages only support desktop and CoreCLR.

and: https://github.com/dotnet/corefx/issues/2576#issuecomment-187184341

I can see that the latest System.Threading.Thread package in the dotnet-core NuGet feed hasn't changed this picture.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138