title: Why can't get the main window handle for a started process?
body: <p>I have a situation where I'm starting a process in my code in order to set up an IPC channel.  The process I'm starting is an MFC application with no CLR support.  The application from which I am starting this process is a C# module in a WPF application (thought I don't think that that is consequential to my problem).  This works with a version of the application that does support CLR, and it works on every computer except the deployment target, a touch screen computer with Windows 7.   But for some reason, when I try it with this exact scenario, the Process object never resolves a main window handle (<code>Process.MainWindowHandle</code>).   Is there another (perhaps even pinvoke) method of doing this?  Is this a security thing?  I'm the one staring the process.  The process's main window handle does exist.  I don't see what could be wrong.</p>
  
  <p>If it helps, here is my code. </p>
  
  <pre><code>        _applicationProcess = new Process();
          _applicationProcess.StartInfo.FileName = _strProcessPath;
          _applicationProcess.StartInfo.Arguments = _strProcessArguments;
          _applicationProcess.Start();
  
          long nTicks = Environment.TickCount;
          if (_applicationProcess.WaitForInputIdle(1 /*minute(s)*/ * 60000))
          {
              try
              {
                  do
                  {
                      // Don't let total processing take more than 1 minute(s).
                      if (Environment.TickCount &gt; nTicks + 1 /*minute(s)*/ * 60000)
                          throw new ApplicationException("MFCApplication.Startup failed! The main window handle is zero!");
  
                      _applicationProcess.Refresh();
                  }
                  while (_applicationProcess.MainWindowHandle.ToInt32() == 0);
  
                  _applicationHandle = new IntPtr(_applicationProcess.MainWindowHandle.ToInt32());
              }
              catch (Exception ex)
              {
                  //Do some stuff...
                  throw;
              }
          }
          else
          {
              // Do exception handling.
          }
  </code></pre>
  
  <p>The <code>ApplicationException</code> is hit after a minute of trying to get a main window handle other than zero.</p>