Results 1 to 5 of 5

Thread: A method .NET really needs

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Between Try & Catch
    Posts
    249

    A method .NET really needs

    I've been wondering this since the beginning of .NET.

    In WinForms, you are able to capture the "Form Closing" event of a form. This is invaluable to me, since it gives me a chance to perform "cleanup" (clearing objects, variables, etc.) before the application is terminated.

    One thing I always wanted was a way to capture the "Window Closing" or, in the case of multi-tabbed browsers, "Tab Closing" event of a browser window.

    Is there currently an industry-accepted method of doing this? There has to be a way, IMO, since secure websites destroy your session once you close the window (so some nosy person can't go through your browser history and see your bank account details).
    If my post helped you, please rate it!

    Languages: VB/ASP.NET 2005, C# 2008,VB6
    Databases: Oracle (knowledge not currently in use), DB2

    FROM Customers
    WHERE We_Know_What_We_Want <> DB.Null
    SELECT *
    0 rows returned

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: A method .NET really needs

    Just so that I'm not misunderstanding anything here.. you're talking about "external" webbrowsers right? Not a WebBrowser control inside of your application?

    To capture a browser closing you have the Exited event of the Process class:
    Code:
            private void Form1_Load(object sender, EventArgs e)
            {
                Process[] p = Process.GetProcessesByName("iexplore");
    
                foreach (Process proc in p)
                {
                    proc.EnableRaisingEvents = true;
                    proc.Exited += new EventHandler(proc_Exited);
                }
            }
    
            void proc_Exited(object sender, EventArgs e)
            {
                Process proc = (Process)sender;
                MessageBox.Show(proc.ProcessName + " exited!");
            }
    Detecting when a Tab has been closed though is a bit tougher, and unless the tab-closing procedure is done in the exact same way in all browsers, I dont see how .NET could be able to capture that.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Between Try & Catch
    Posts
    249

    Re: A method .NET really needs

    That looks like a Windows form, am I right?

    I'm talking about an external web browser.
    If my post helped you, please rate it!

    Languages: VB/ASP.NET 2005, C# 2008,VB6
    Databases: Oracle (knowledge not currently in use), DB2

    FROM Customers
    WHERE We_Know_What_We_Want <> DB.Null
    SELECT *
    0 rows returned

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: A method .NET really needs

    Hey,

    What Atheist has provided is a sample of some code that you could put into a Windows Form application, but it detects the closure of an external process, in this case iexplore (Internet Explorer) and it alerts a MessageBox when this happens.

    Is that what you want?

    This approach will get slightly harder given that in newer web browsers, each tab runs as it's own process, but you may well be able to do something.

    Gary

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: A method .NET really needs

    Are you talking about creating an ASP.NET application yourself, and you want your page to detect when it's unloaded? If so then it's an ASP.NET issue and this thread belongs there. To that end, the Page class does have an Unload event.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width