Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if browser closed manually

In visual studio 2010, working with c#;

I open a browser with:

private IE browser;

private void Set_Browser()
{
    string splashUrl = "google.com";
    browser= new IE(splashUrl);
}

If a user(person) closes the browser by accident, then my application will not be able to work anymore.

QUESTIONS:

  1. So how do I check if a user closed the browser manually?
  2. Can I unable a user from closing the browser by adding the browser to my application GUI as a control? [using Windows Forms]
  3. -> How do I do that?

Last question related to this post How to use watin with WebBrowser control? (2 years old, but no decent answer too)

EDIT: The solution in give URL seems to work. Problem is that if I try to send the WebBrowser.ActivateX.. as an object to other class. Then my browser = new IE(..) returns null. It does work when I instantiate it in the form class though. Any solutions?

like image 579
dylanmensaert Avatar asked Nov 16 '25 15:11

dylanmensaert


1 Answers

You can search for the process of internet explorer every x seconds and see if the browser is already running using this code:

    bool isRunning = false;
    foreach (Process clsProcess in Process.GetProcesses()) {
            if (clsProcess.ProcessName.Contains("iexplore"))
            {
                    isRunning = true;
                    break;
            }
    }

You can use this article

Or you can add a browser control to your application using this article

like image 130
Sawan Avatar answered Nov 19 '25 05:11

Sawan