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?
Suspends the current thread for the specified number of milliseconds.
NET Core is that you can run it on multiple platforms and architectures. So you can build an app that will run on Windows, but also on Linux, macOS and on different architectures like x86 and ARM. This is perfect for lots of scenarios, including desktop applications. You can learn about other reasons for using .
In c#, the sleep method is useful to suspend or pause the current thread execution for a specified time. We can suspend the thread execution either by passing the time in milliseconds or with TimeSpan property like as shown below. TimeSpan ts = new TimeSpan(0,0,1);
Sleep method. Calling the Thread. Sleep method causes the current thread to immediately block for the number of milliseconds or the time interval you pass to the method, and yields the remainder of its time slice to another thread. Once that interval elapses, the sleeping thread resumes execution.
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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With