The name "Thread" does not exist in the current context

When I put this code Thread.Sleep(2000); he gives me an error:

The name "Thread" does not exist in the current context. "

I have already enabled the namespace using System.Threading; . See System.Threading.Thread.Sleep() on MSDN .

+7
c # namespaces visual-studio-2013
source share
2 answers

I assume this is a portable class library or a Windows Store / Phone project focused on Windows Runtime that does not have this design.


An alternative and recommended way would be to use:

await Task.Delay(TimeSpan.FromSeconds(2));

or for a blocking call if you are not in an asynchronous context:

Task.Delay(TimeSpan.FromSeconds(2)).Wait();

A similar problem is also revealed in this post .

+9
source share

Try using the full namespace in your code:

 System.Threading.Thread.Sleep(1000); 
+4
source share

All Articles