views:

27

answers:

2

I have one VB.net ClassLibray application.

I have a line of code:

System.Diagnostics.Process.Start("http://stackoverflow.com/")

This will take me to stackoverflow website.

the question is when i close the stackoverflow website how to get a response back to my application ?

ie,

How to handle the sessions of external web pages in .net ?

A: 

There is no general way to do this. There is no way to know what process will be started when you call that method.

For example, it might start any installed browser, such as Firefox, IE, Safari, or Opera.

Even if you know what browser it is there is no way to know what the process is. Many new browsers support tabbed UI or run in multiple processes. There is no way to know which process or which tab in a process will handle this URL.

It also isn't clear what you mean by "session". What exactly are you hoping to do here?

Eilon
A: 

The Process.Start function returns a Process object which has a HasExited property. You can simply check this.

Alternatively you can call WaitForExit if you simply want your application to stop until the browser closes (Optionally with a timeout if you for example only want to wait a few minutes before falling back to a default functionality).

Tim Schneider
Please refer to my answer for a number of reasons why this is not a reliable way to do this.
Eilon
Nope, that won't work for websites. Calling Process.Start with a URL returns null - you can't do ANYTHING with it!
Eric Mickelsen
Ah, I didn't realize that tehMick, I guess this technique would only work if you explicitly called a browser's exe with the URL, which sorta sucks cause you wouldn't be obeying their default browser. And yeah Eilon it could be unreliable depending on how the browser handles it's processes, but short of searching System.Diagnostics.Process.GetProcessesByName for anything that looks like a browser (Which has it's own problems) it's as good as you'll get.
Tim Schneider