|
-
Apr 9th, 2009, 02:57 PM
#1
Thread Starter
Addicted Member
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
-
Apr 9th, 2009, 04:20 PM
#2
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.
-
Apr 9th, 2009, 07:04 PM
#3
Thread Starter
Addicted Member
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
-
Apr 11th, 2009, 03:48 AM
#4
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
-
Apr 14th, 2009, 11:31 PM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|