Using SendMessage() to minimize all windows, but need a more efficient way than Thread.Sleep() to wait until the legacy desktop is showing
<p>In my C# console application, I am using <code>SendMessage()</code> to minimize all windows, effectively showing the Windows 8 Legacy Desktop.  This works great, but I have to use a <code>Thread.Sleep(1000)</code> in order to wait for the Legacy Desktop to actually show before before I try to do anything else.</p>

<pre><code>IntPtr lHwnd = FindWindow("Shell_TrayWnd", null);
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL, IntPtr.Zero);
Thread.Sleep(1000);
</code></pre>

<p>I really want to replace the <code>Thread.Sleep()</code> with a more efficient way to detect that the Legacy Desktop is showing before continuing on.</p>

<p>Any ideas?</p>

<p>Edit:
Here are the Interop wrappers and constants.  just in case it helps..</p>

<pre><code>[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);

const int WM_COMMAND = 0x111;
const int MIN_ALL = 419;
const int MIN_ALL_UNDO = 416;
</code></pre>
