System.Diagnostics.Process Questions 
Author Message
 System.Diagnostics.Process Questions

First, here's my code:

------snip-----

private void button1_Click(object sender, System.EventArgs e)
{
    string address = " http://www.*-*-*.com/ ";
    label2.Text = "Loaded";
    Process explorer = new Process();
    explorer.EnableRaisingEvents = true;
    explorer = Process.Start("IEXPLORE", address);
    explorer.WaitForInputIdle();
    label2.Text = "Loaded";
    Debug.WriteLine("Process ID = " + explorer.Id);
    Debug.WriteLine(explorer.ToString());

Quote:
}

------snip-----

So.. on the press of this button, Internet Explorer starts up.  Well, I want
to do more stuff when it opens up, but I have to wait for it to get fully
loaded.  That's why I used the .WaitForInputIdle() method.  It works
splended the first time I run the application.  I can tell because the
"Loaded" text shows up and Debug output only after I see IE fully loads.

Unfortunately, it doesn't work if I press the button a second time.  The
"Loaded" label and debug output show up instantly before IE loads.  So some
of the commands I want to execute after it loads are missed because IE is
too busy loading.

I have a feeling it has something to do with my Process component not
knowing if or when the process exits.  But I'm not sure.  I thought maybe
.Refresh() would help, but it doesn't.

Can someone help?  Thanks!



Mon, 27 Jun 2005 13:36:08 GMT  
 System.Diagnostics.Process Questions

Correction in my code:
the label2.Text is initialized to "" in the 2nd line

So it looks like this.

 ------snip-----

 private void button1_Click(object sender, System.EventArgs e)
 {
     string address = "http://www.google.com";
     label2.Text = "";
     Process explorer = new Process();
     explorer.EnableRaisingEvents = true;
     explorer = Process.Start("IEXPLORE", address);
     explorer.WaitForInputIdle();
     label2.Text = "Loaded";
     Debug.WriteLine("Process ID = " + explorer.Id);
     Debug.WriteLine(explorer.ToString());
 }

 ------snip-----



Mon, 27 Jun 2005 13:39:17 GMT  
 System.Diagnostics.Process Questions
Eric,

Why don't you directly reference the IE and use it. It would help you in
using IE's specific events too.
Here is part of your code edited (remember to reference SHDocVw):
private void button1_Click(object sender, System.EventArgs e)

{

object o = null;

object s = "http://www.google.com";

label1.Text = "";

InternetExplorer tmp;

tmp = new InternetExplorer();

tmp.Visible = true;

DWebBrowserEvents2_NavigateComplete2EventHandler

DBeforeNavigateE = new
DWebBrowserEvents2_NavigateComplete2EventHandler(myNavigate);

tmp.NavigateComplete2 += DBeforeNavigateE;

tmp.Navigate2(ref s , ref o, ref o, ref o, ref o);

Quote:
}

void myNavigate(object o, ref object e)

{

label1.Text = "Loaded";

Quote:
}

Cheers,
Thilak


Quote:

> Correction in my code:
> the label2.Text is initialized to "" in the 2nd line

> So it looks like this.

>  ------snip-----

>  private void button1_Click(object sender, System.EventArgs e)
>  {
>      string address = "http://www.google.com";
>      label2.Text = "";
>      Process explorer = new Process();
>      explorer.EnableRaisingEvents = true;
>      explorer = Process.Start("IEXPLORE", address);
>      explorer.WaitForInputIdle();
>      label2.Text = "Loaded";
>      Debug.WriteLine("Process ID = " + explorer.Id);
>      Debug.WriteLine(explorer.ToString());
>  }

>  ------snip-----



Mon, 27 Jun 2005 16:07:25 GMT  
 System.Diagnostics.Process Questions
Hi.. it works great!!

Can you please explain this portion of the code?

DWebBrowserEvents2_NavigateComplete2EventHandler

DBeforeNavigateE = new
DWebBrowserEvents2_NavigateComplete2EventHandler(myNavigate);

tmp.NavigateComplete2 += DBeforeNavigateE;



Tue, 28 Jun 2005 01:20:50 GMT  
 System.Diagnostics.Process Questions
Eric,

Good to hear that the code helped.

This is basically setting up an event (just like any other event) which
would be fired after IE finishes completely downloading
the page. You think this is something different just because of the huge
name it has got. Well that is how
the .net builds it when you reference a typelib.

A shorter form of setting the event is as follows:
tmp.NavigateComplete2 += new
DWebBrowserEvents2_NavigateComplete2EventHandler(myNavigate);

Cheers,
Thilak


Quote:
> Hi.. it works great!!

> Can you please explain this portion of the code?

> DWebBrowserEvents2_NavigateComplete2EventHandler

> DBeforeNavigateE = new
> DWebBrowserEvents2_NavigateComplete2EventHandler(myNavigate);

> tmp.NavigateComplete2 += DBeforeNavigateE;



Tue, 28 Jun 2005 13:48:37 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Working with System.Diagnostics.Process

2. System.Diagnostics.Process, WaitForExit

3. System.Diagnostics.Process.Start

4. Executing Old 16 Bit DOS Apps from C# via System.Diagnostics.Process

5. Capturing stdout using System.Diagnostics.Process.Start

6. Diagnostics.Process.Start from Windows Service Question

7. Diagnostics.Process.Start from Windows Service Question

8. Can't Resolve System::Diagnostics::Debug

9. Windows service applications (System.Diagnostics.DebuggableAttribute headaches)

10. C# System.Diagnostics

11. Completely STUMPED: 'System.Diagnostics.DebuggableAttribute'

12. declaration issue with system.diagnostics

 

 
Powered by phpBB® Forum Software