title: Don't execute next line until Process.Start is complete
body: <p>I'm writing a simple C# console application which opens up four instances of Windows Explorer and uses Pinvoke's <code>MoveWindow</code> to place them around the screen. My problem is that the <code>Process.Start</code> command seems to run too slowly, and the <code>MoveWindow</code> function cannot find the process unless I deliberately slow the program down. Here is my code:</p>
  
  <pre><code>Process.Start(new ProcessStartInfo()
  {
      FileName = "explorer",
      Arguments = location,  //Defined elsewhere (for testing just ".")
      UseShellExecute = false
  });
  int[] pos = GetPositions(position); //Little function which gets the positions I want for this window
  System.Threading.Thread.Sleep(500);
  IntPtr hnd = GetForegroundWindow();
  bool ok = MoveWindow(hnd, pos[0], pos[1], pos[2], pos[3], false);
  </code></pre>
  
  <p>See how I'm having to <code>Sleep</code> for an (arbitrary) half second. It's not ideal, because I don't know the specifications of the machine it will be running on. It could end up being either inefficient on a fast machine or could break on a slower machine. Is there a more concrete way of waiting until a process has started where I don't have to arbitrarily wait for a set time?</p>
  
  <hr/>
  
  <p>Also, on a semi-related note, you may notice a bit of cowboy code which just gets the foreground window to grab the window I want moved. This is because I had an absolute mare trying to pick out specific Window Explorer processes. From what I can tell they just don't work the same way as anything else (like when I was testing with notepad or IE) and just passing a handle doesn't work. Anyone who's familiar with this problem, feel free to contribute, but if not don't spend any time on it - clunky as this solution is, it works, and for a little application I don't want to spend hours bashing my head against the keyboard trying to figure out the proper way of doing it.</p>