title: SetWindowLong Hanging
body: <p>Why does <code>SetWindowLong(myForm.hWnd, GWL_HWNDPARENT, parentHwnd)</code> hang?</p>
  
  <p>I can recreate this problem consistently doing these three steps.</p>
  
  <ol>
  <li>Create the .NET Form</li>
  <li>Initalize the WaitWindow COM object, call ShowWindow on the COM object while passing the .NET Forms Handle</li>
  <li>In VB6 invoke the SetWindowLong method</li>
  </ol>
  
  <p><strong>C# Windows Application (Hangs)</strong></p>
  
  <pre><code>private static void Main(string[] args)
  {
        Form form = new Form();
        form.Show();
  
        Interop.WaitWindow waitWindow = new Interop.WaitWindow();
        waitWindow.ShowWindow(form.Handle.ToInt32(), Language.RISEnglish);
  }
  </code></pre>
  
  <p><strong>C# Console Application (Doesn't Hang)</strong></p>
  
  <pre><code>private static void Main(string[] args)
  {
        IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;     
  
        Interop.WaitWindow waitWindow = new Interop.WaitWindow();
        waitWindow.ShowWindow(handle.ToInt32(), Language.RISEnglish);
  }
  </code></pre>
  
  <p><strong>VB6 Code Snippet</strong></p>
  
  <pre><code>Public Sub ShowWindow(ByVal parentHwnd As Long, ByVal language As Language)
  
      SetWindowLong(myForm.hWnd, GWL_HWNDPARENT, parentHwnd)  'Hangs Here
      CenterWindow (parentHwnd)
  
      myForm.ShowRetrieving (language)
      myForm.Show (vbModal)
  End Sub
  </code></pre>
  
  <p>Really would appreciate your help :)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I do understand that SetWIndowLong shouldn't be called to change the parent but I'm trying to understand why it hangs only when a .NET form handle is used.</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>I now believe the issue is not related to SetWindowLong but the actual handle itself.  I'm still investigating but it appears that when I call the VB6 code from .NET it creates an RPC thread.  I'm not sure yet but I have a feeling it has something to do with a cross-threading issue.</p>