19

Mostly out of curiosity, I started programming a small "Metro Style" project in Visual Studio 2011, the one that was released in Windows Developer Preview. It combines XAML for the design and C# (in my project) for the code-behind.

The C# experience is mostly identical to the one you get on Visual Studio 2008 with .NET framework 4.0, save for these features that I wasn't able to find :

  • System.Console, which make debugging a bit more difficult,
  • And System.Threading.Thread.Sleep(TimeSpan), which is a bit more inconvenient since that's exactly what I needed right now.

So are these features actually missing / disabled, or did I just look in the wrong place ? Thanks in advance.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
Timst
  • 930
  • 1
  • 11
  • 26

4 Answers4

17

I don't have the Preview installed, so I can't check. But here are two thoughts:

  1. System.Console is probably not available, because there is no Console in Metro style applications. Check if Debug.WriteLine is available. It writes directly to the Debug window in Visual Studio.

  2. Metro style applications are not supposed to block threads for extended durations. Everything that takes more than a few milliseconds should be done in an asynchronous way. Look for some way to execute an asynchronous callback after some time, e.g., a timer. Or you might be able to await the end of a time span (like TaskEx.Delay in the Async CTP).

dtb
  • 213,145
  • 36
  • 401
  • 431
7

For "printf debugging", I suggest that you use Debug.WriteLine and/or Trace.WriteLine methods from System.Diagnostics namespace. They print to the debugger output window - in VS Express that comes in Developer Preview, you'll need to enable that first (Debug -> Windows -> Output).

For Thread.Sleep, can you clarify the specific scenario for which you believe it to be needed?

Pavel Minaev
  • 99,783
  • 25
  • 219
  • 289
  • 1
    Thanks, Debug.Write worked. As for Thread.Sleep, I needed it to quickly prototype a loop, but the Task.Delay proposed by the answer above filled the gap nicely. – Timst Sep 17 '11 at 10:07
  • Great solution - this is the equivalent of Trace.WriteLine() in WPF in the System.Diagnostics namespace. – Shawn J. Molloy Nov 23 '13 at 23:06
6

http://dougseven.com/2011/09/15/a-bad-picture-is-worth-a-thousand-long-discussions/

My understanding is that it's just a subset; most of what is missing relates to synchronous operations (so I'm not surprised that Thread.Sleep() is gone). You'll also find things like 'File.Create' cannot be called synchronously.

Rob P.
  • 14,921
  • 14
  • 73
  • 109
5

There is no Thread.Sleep(), but you can use Task.Delay(milliseconds);

For those wondering what is it useful for, I say I use it in debug to stress async behaviour.

Adi Lester
  • 24,731
  • 12
  • 95
  • 110