Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting application pool name in recycle
Message
From
24/11/2013 13:29:48
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Getting application pool name in recycle
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01588578
Message ID:
01588578
Views:
49
In my framework, I have a Global.vb class such as this, which contains partially the following:
Imports System.Web
Imports System.Reflection

Public Class GlobalBase
    Inherits System.Web.HttpApplication

    Private oApp As Framework.App = Nothing

    Sub Application_End()
        Dim lcShutDownMessage As String = ""
        Dim lcShutDownStack As String = ""
        Dim lnDateNow As Double = Date.Now.Ticks
        Dim lnDuration As Double = 0
        Dim loHttpRuntime As HttpRuntime = Nothing
        Dim loUpdate As Framework.Update = Nothing

        oApp = App.oApp

        loUpdate = New Framework.Update(oApp)

        ' If we have an IISApplicationCycle table
        If Not oApp.Tables("IISApplicationCycle") Is Nothing Then
            lnDuration = ((lnDateNow - oApp.nDateNow) / 10000000)

            loHttpRuntime = DirectCast(GetType(System.Web.HttpRuntime).InvokeMember("_theRuntime", _
             BindingFlags.NonPublic Or BindingFlags.Static Or BindingFlags.GetField, Nothing, Nothing, Nothing), HttpRuntime)

            ' If it is running
            If Not loHttpRuntime Is Nothing Then

                lcShutDownMessage = DirectCast(loHttpRuntime.[GetType]().InvokeMember("_shutDownMessage", _
                 BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.GetField, Nothing, loHttpRuntime, Nothing), String)

                lcShutDownStack = DirectCast(loHttpRuntime.[GetType]().InvokeMember("_shutDownStack", _
                 BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.GetField, Nothing, loHttpRuntime, Nothing), String)

            End If

            ' Update the record
            loUpdate.cAlias = "IISApplicationCycle"
            loUpdate.nPrimaryKey = oApp.nID
            loUpdate.ParameterAdd("Duration", lnDuration)
            loUpdate.ParameterAdd("ShutDownMessage", lcShutDownMessage)
            loUpdate.ParameterAdd("ShutDownStack", lcShutDownStack)
            If Not loUpdate.Update() Then
                Exit Sub
            End If

        End If

    End Sub

End Class
The application pool are set to recycle at 06h00.

When that happens, the already created records in an IISApplicationCycle table I have will get completed. They are created when the application pool worker process starts. So, basically, if I have two application pools having 4 worker process each, that will result in 8 records being logged. When they are created, I keep the primary key of the record having been created in oApp.nID and the startup time. This allows me to know which record to update and to initialize the Duration field.

For the ShutDownMessage and ShutDownStack, this is obtained as shown above.

But, what I do not have here is the application pool name. Would there be a way here with the reflection approach to obtain the application pool name? Or, is it something I should get when the record is created. When the record is created, I obtain the worker process ID as this:
' Get the process ID
oApp.nProcessID = Process.GetCurrentProcess().Id
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform