using event newwindow2 and newwindow3 of the axwebbrowser BUT to open a new form in a new thread

Jan 24 2010 11:52 AM

Hi:
I wrote an application that use the axWebbrowser control (not the webbrowser that came with .net 2.0) and till now, when a new windowsevent was occurs, I used the following code that works ok:
   private void axWebBrowser1_NewWindow2(object sender,
      AxSHDocVw.DWebBrowserEvents2_NewWindow2Event e)
  {
     Form1 frmWB;
     frmWB = new Form1();
     frmWB.axWebBrowser1.RegisterAsBrowser = true;
     e.ppDisp = frmWB.axWebBrowser1.Application;
     frmWB.Visible = true;
  }
Now, I want to create the new form in a new trhead, in order to prevent that, in case that the main form will be close, the second one (just created) must be NOT closed and remains open.
For this, I have the following code, but I don't know how to set the e.ppDisp in order that the newForm created in a separate thread can receive the passed uRL:

 private void axWebBrowser1_NewWindow3(object sender,
    AxSHDocVw.DWebBrowserEvents2_NewWindow3Event e)
 {
     System.Threading.Thread t =
           new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ThreadProc));
     t.SetApartmentState(ApartmentState.STA);
     t.Start(e);
 }

  public static void ThreadProc(object e)
 {
    AxSHDocVw.DWebBrowserEvents2_NewWindow3Event f =
      (AxSHDocVw.DWebBrowserEvents2_NewWindow3Event)e;
    Form1 newForm = new Form1();
    // THE PROBLEM IS HERE, how can I use the previous sentences
    // newForm.axWebBrowser1.RegisterAsBrowser = true;
    // e.ppDisp = newForm.axWebBrowser1.Application;
    // because now the newForm is in a separate thread
    Application.Run(newForm);
 }

I tried:
public static void ThreadProc(object e)
{
 AxSHDocVw.DWebBrowserEvents2_NewWindow3Event f =
  (AxSHDocVw.DWebBrowserEvents2_NewWindow3Event)e;
 Form1 nF = new Form1(false);
 nF.axWebBrowser1.RegisterAsBrowser = true;
 f.ppDisp = nF.axWebBrowser1.Application;
 nF.Visible = true;
 Application.Run(nF);
}

but the result is:
a) a new Form is created that not navigate to nothing.
b) a InternetExplorer window is open with the desired page where I want to navigate to... but I need to navigate into my app, not IE !

Thanks in Advance
Ernesto Aides
Ashdod - Israel