Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Global class constructor and Application_Start method

Posted on 2006-11-17
9
Medium Priority
?
531 Views
Last Modified: 2011-10-03
How do these two functions of the Global class in Global.asax differ?

1)constructor - public Global()
2)Application_Start - protected void Application_Start(Object sender, EventArgs e)

Please help. Thank you.
0
Comment
Question by:engg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17978764
There is a specific chain of events in the lifetime of an application.  

The constructor is called when the class is instantiated through code.  The Application_Start is an event handler when the application is started.

Reference:

ASP.NET Application Life Cycle Overview
http://msdn2.microsoft.com/en-gb/library/ms178473.aspx

<Quote>The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance.</Quote>

Bob
0
 

Author Comment

by:engg
ID: 17992440
Thanks Bob. I will read this article and I will get back soon.
0
 

Author Comment

by:engg
ID: 18057265
Quote from the above MSDN article:
<Quote>The first time an ASP.NET page or process is requested in an application, a new instance of HttpApplication is created. However, to maximize performance, HttpApplication instances might be reused for multiple requests..</Quote>

So suppose the application has been built and it receives 100 requests during the day.

Then Application_Start() method will be called exactly ONCE during that day.
But constructor Global() will be called 'n' number of times during that day where  1<= n <= 100.

Please correct me if I am wrong.


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 18076375
No, I don't believe that the Global class is instantiated for each request, so the constructor will only be called when the class is created.  There really isn't much difference between Application_Start and the Global constructor, other than when in the application's life cycle they are called.

Bob
0
 

Author Comment

by:engg
ID: 18077020
Thanks Bob.
So what's the best place to add the code which we want to execute on every web request? - the code which operates on global data that is accessible throughout the application.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 2000 total points
ID: 18077115
Now we're gettin' down to it :)

If you need to run code on every request, then add it to the Application.BeginRequest event handler:

  protected void Application_BeginRequest(Object sender, EventArgs e)
  {
  }

Bob

0
 

Author Comment

by:engg
ID: 18078107
yeah :).
It works for me. Thanks Bob.
One more thing - I am reading about HttpApplication.Init and HttpApplication.Dispose. Could you give an example when could it be useful to override these methods?
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 2000 total points
ID: 18078191
Now there's a subject that hasn't come up before.  I don't know when it would be useful to use the HttpApplication.Init and HttpApplication.Dispose methods.

There are very few resources for those methods.  I could imagine that if you want to override the default event chain or HTTP modules, then you would think about using it.  Otherwise, it has never been a topic of discussion in all my time with ASP.NET.

Bob
0
 

Author Comment

by:engg
ID: 18078252
Thank you very much, Bob
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question