Search KB Filter article types
Form Concepts CodeSample - Detecting Browser close
Categories: Forms, Browser Refresh & Suspend
Tags: Developers, Events, Windows & Dialogs, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
Revision: 1
Posted: 04/Oct/2009
Updated: 23/July/2010
Status: Publish
Types: Code

This article will have a few sections added to it soon, based on the following article type skeleton: CodeSample
Overview

As all application that run over the Visual WebGui framework are basically web-applications and there is no browser standard for notifying the server that the browser:

  • has been closed
  • the user refreshed the page
  • that the user moved to a different website

we have no specific way of notifying you which of these three specific events occurred.

In version 6.1.1 we have added an event that is fired when any one of the three previously actions has occurred.

VB.NET Code

Note that the VB.NET code adds logging of the event firing to a file on the server.

Imports Gizmox.WebGUI.Forms
Imports System.IO
Public Class DetectBrowserClose
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler Application.ThreadSuspend, AddressOf Application_ThreadSuspend
    End Sub
 
    Private Sub Application_ThreadSuspend(ByVal sender As Object, ByVal e As EventArgs)
        Dim f As StreamWriter = New StreamWriter("c:\temp\ts.txt")
        f.WriteLine("Thread suspended " + DateTime.Now.ToString())
        f.Close()
        VWGContext.Current.Terminate(True)
    End Sub
End Class

C# Code
 
public void RegisterThreadSuspendHandler()
{
Application.ThreadSuspend += new EventHandler(Application_ThreadSuspend);
}
 
void Application_ThreadSuspend(object sender, EventArgs e)
{
   using (StreamWriter sw = new StreamWriter(@"c:\temp\ts.txt"))
   {
      sw.WriteLine("Thread suspended " + DateTime.Now.ToString());
   }
   ((IContextTerminate)VWGContext.Current).Terminate(true);
}

About the author

Related Articles

Forms  
Title Update Author
Tags: Developers, Windows & Dialogs, C#, XML, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
11/Jan/2007    2007/01/11
Tags: Architects, Developers, Windows & Dialogs, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04
Tags: Developers, Theme, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
23/July/2010    2010/07/23
Tags: Developers, Events, Navigation, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
04/Dec/2010    2010/12/04
Tags: Architects, Developers, Windows & Dialogs, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04
Tags: Architects, Developers, Navigation, Windows & Dialogs, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
24/May/2010    2010/05/24
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS