Link to home
Start Free TrialLog in
Avatar of MarcGraff
MarcGraffFlag for United States of America

asked on

Rerun Application_Start?

How would one programmatically rerun Application_Start?

Thanks!
   - Marc
Avatar of AGBrown
AGBrown
Flag of United Kingdom of Great Britain and Northern Ireland image

Its a tough one. Basically, as far as I know, you can't. I think the Application_Start method is kicked off by the inner workings of the HttpApplication object and its factory.

But, there is a better solution in terms of "code design" anyway; this would be to extract your code into a seperate class, and then call that class's methods from Application_Start and any other place you want it called.

Andy
Avatar of MarcGraff

ASKER

Good Morning AGBrown,

My objective is to reload the "Application" variables. I have tryed to create a seporate class but each time it has failed.

My closest attempt:
    Public Sub ReloadVars(ByVal oGlobal As System.Web.HttpApplication)
        oGlobal.Application.Add("TestName", "TestValue")
    End Sub

but I do not know what to pass into this from the "reset" page.

Thanks!
   - Marc
SOLUTION
Avatar of AGBrown
AGBrown
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good day AGBrown,
I am working with the code below but it does not retain the Application variables in the global or page context. Any other suggestions?

In Global.asax.vb:
    Public Sub AppReset(ByVal bClearRecSets As Boolean, ByVal bDisplay As Boolean)
        Dim oApp As New App_Reset
        oApp.ReloadVars(bClearRecSets, bDisplay)
    End Sub


In ReloadVars:
Public Class App_Reset
    Public Sub ReloadVars(ByVal bClearRecSets As Boolean, ByVal bDisplay As Boolean)

        HttpContext.Current.Application.Add("Test", "TestValue")
   End Sub
End Class

On ResetPage:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim APP_Vars As New App_Reset
        APP_Vars.ReloadVars(False, False)
    End Sub
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks so much Andy for all of your help! And sorry it took me so long to get this up and running!
No problem, glad you solved it.

Andy