Rerun Application_Start?

How would one programmatically rerun Application_Start?

Thanks!
   - Marc
LVL 1
MarcGraffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AGBrownCommented:
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
0
MarcGraffAuthor Commented:
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
0
AGBrownCommented:
Hi Marc,

Try writing your method as:

Public Sub ReloadVars()
      HttpContext.Current.Application.Add("TestName", "TestValue")
End Sub

or

Public Sub ReloadVars()
      HttpContext.Current.Application("TestName") = "TestValue"
End Sub

Note that the "Application" property in Global, or in a web page is simply a wrapper for the HttpContext.Current.Application property, so they are one and the same.

Andy
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

MarcGraffAuthor Commented:
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
0
AGBrownCommented:
That's slightly confusing. I have a few ideas to find out what is happening:
1) Put a breakpoint on the line "APP_Vars.ReloadVars(False, False)" in Page_Load. Run your application in debug. When it hits, put a watch on the application object for the key "Test" (i.e. on Application("Test"). Does that value equal "TestValue"?

2) If not, then where does AppReset get called from? Do you have a call to it in the Application_Start method in the global.asax.cs? If you put a breakpoint on the line oApp.ReloadVars(bClearRecSets, bDisplay) and run your application again, does it hit?

3) Put a line of foo code after the call to ReloadVars in AppReset:

Public Sub AppReset(ByVal bClearRecSets As Boolean, ByVal bDisplay As Boolean)
        Dim oApp As New App_Reset
        oApp.ReloadVars(bClearRecSets, bDisplay)
        Dim foo As String = ""
End Sub

Put the breakpoint on Dim foo As String = "", run the application again and put a watch on Application("Test"). Does that value equal "TestValue" now? It should do. If not then something very strange is happening in your application.

Andy
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarcGraffAuthor Commented:
Thanks so much Andy for all of your help! And sorry it took me so long to get this up and running!
0
AGBrownCommented:
No problem, glad you solved it.

Andy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.