System.InvalidOperationException on WaitForInputIdle

  • Thread starter lovecreatesbea...
  • Start date
L

lovecreatesbea...

I want to start an IE instance within a Windows Form program, and put
the IE browser onto the secondary monitor.

But I got an exception at the following LINE 5 of the C# code when
called WaitForInputIdle on a process. Could you please help me out of
this trouble? Thank you.

private void button2_Click(object sender, EventArgs e)
{
Process p1 = new Process();
Process.Start("IExplore.exe", "www.google.com");
p1.WaitForInputIdle(2000); /LINE 5:
*System.InvalidOperationException */
IntPtr h1 = p1.MainWindowHandle;
Form f1 = (Form)Control.FromHandle(h1);
f1.DesktopLocation = Screen.AllScreens[0].Bounds.Location;
f1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f1.DesktopBounds = Screen.AllScreens[0].Bounds;
}
 
L

lovecreatesbea...

I want to start an IE instance within a Windows Form program, and put
the IE browser onto the secondary monitor.

But I got an exception at the following LINE 5 of the C# code when
called WaitForInputIdle on a process. Could you please help me out of
this trouble? Thank you.

private void button2_Click(object sender, EventArgs e)
{
Process p1 = new Process();
Process.Start("IExplore.exe", "www.google.com");
p1.WaitForInputIdle(2000); /LINE 5:
*System.InvalidOperationException */
IntPtr h1 = p1.MainWindowHandle;
Form f1 = (Form)Control.FromHandle(h1);
f1.DesktopLocation = Screen.AllScreens[0].Bounds.Location;
f1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f1.DesktopBounds = Screen.AllScreens[0].Bounds;
}

I've made some progress on my last code snippet. This time I get a
System.NullReferenceException on the Form object at Line #11.

Could you please help me to correct this?

private void button2_Click(object sender, EventArgs e)
{
Process p1 = new Process();
p1.StartInfo.FileName = "IExplore.exe";
p1.StartInfo.Arguments = "www.google.com";
p1.Start();
p1.WaitForInputIdle(2000);
IntPtr h1 = p1.MainWindowHandle;
Form f1 = new Form();
f1 = (Form)Control.FromHandle(h1);
f1.DesktopLocation = Screen.AllScreens[0].Bounds.Location; /*LINE
11: System.NullReferenceException*/
f1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f1.DesktopBounds = Screen.AllScreens[0].Bounds;
}
 
L

lovecreatesbea...

I want to start an IE instance within a Windows Form program, and put
the IE browser onto the secondary monitor.
But I got an exception at the following LINE 5 of the C# code when
called WaitForInputIdle on a process. Could you please help me out of
this trouble? Thank you.
private void button2_Click(object sender, EventArgs e)
{
Process p1 = new Process();
Process.Start("IExplore.exe", "www.google.com");
p1.WaitForInputIdle(2000); /LINE 5:
*System.InvalidOperationException */
IntPtr h1 = p1.MainWindowHandle;
Form f1 = (Form)Control.FromHandle(h1);
f1.DesktopLocation = Screen.AllScreens[0].Bounds.Location;
f1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f1.DesktopBounds = Screen.AllScreens[0].Bounds;
}

I've made some progress on my last code snippet. This time I get a
System.NullReferenceException on the Form object at Line #11.

Could you please help me to correct this?

private void button2_Click(object sender, EventArgs e)
{
Process p1 = new Process();
p1.StartInfo.FileName = "IExplore.exe";
p1.StartInfo.Arguments = "www.google.com";
p1.Start();
p1.WaitForInputIdle(2000);
IntPtr h1 = p1.MainWindowHandle;
Form f1 = new Form();
f1 = (Form)Control.FromHandle(h1);
f1.DesktopLocation = Screen.AllScreens[0].Bounds.Location; /*LINE
11: System.NullReferenceException*/
f1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f1.DesktopBounds = Screen.AllScreens[0].Bounds;
}

In the following code snippet, the control flow reaches line #16 and
an exception is thrown then. I'm now having two doubts on this
failure:

1) I'm not sure if I declare and assign the Form object correctly.

2) Can Control.FromHandle() be used upon an IExplore.exe browser
window that isn't a .net object? If this really can't be done, can I
use another way to position this kind of window on the second monitor?

private void button2_Click(object sender, EventArgs e)
{
Process p1 = new Process();
p1.StartInfo.FileName = "IExplore.exe";
p1.StartInfo.Arguments = "www.google.com";
p1.Start();
p1.WaitForInputIdle(2000);

while (true){
if ((p1.Id >= 0) & (p1.Responding)){
//get the MainWindowHandle from it
IntPtr h1 = p1.MainWindowHandle;
Form f1 = new Form();
f1 = (Form)Control.FromHandle(h1);
f1.DesktopBounds = Screen.AllScreens[0].Bounds; /*LINE 16:
System.NullReferenceException*/
break;
}
}
}
 
L

lovecreatesbea...

On Aug 9, 5:43 pm, "(e-mail address removed)"

I give up starting an ie instance now, I use a WebBrowser control to
do the task instead, and it works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top