asp.net - explain why an object has lifetime outside scope -


I have written a class as I wrote in keeping this in mind that it is primarily for use on the web ( I.e. it will be used with ASPX pages).

  Public Class TestHelper {Public TestHelper () {HttpContext ctxt = HttpContext. Current; IHttpHandler RequestHandler = ctxt.Handler; Page current page; Current page = (page) request handler; CurrentPage.Unload + = New EventHeader (current page_download); Debug Print ("Open All Connections Here ..."); } Zero CurrentPage_Unload (Object Sender, EventArgs e) {Debug.Print ("Close all connections here ..."); }}  

And I have written the code of my aspx page behind this:

  public partial class _Default: System.Web.UI.Page {protected Zero Page_load (object sender, eventAgps E) {test helper helper = new test helper (); Accessory = null; }}  

Despite supporting 'abnormal', I feel that CurrentPage_Unload () is executed. Why is this behavior? What is this behavior commonly called?

I have written class in that style, for this reason I thought that managing my DB connection in a central fashion in class could do the best. Typically people will call the object after the helper.IsValid () , followed by helper.ProfileExists () behind the ASPX code. Each of these methods will have their own DB Connection Objects (IDBCNation), and their respective open () & amp; Close () DB connection to open / close the call I thought we should do this once in the code. So I used the constructor to open the DB connection to close the connection objects and the unload event of the page object. Is there any disadvantage for writing classes like this? Assigning

zero to the variable does not end its actual life span. Because .NET uses non-deterministic garbage collection system (where objects are purified on a number of criteria from time to time, as they come out of the field), you ever can not trust being gathered before it ends the process before it

Also, because you are adding an event handler (i.e., a representative in which your reference to a newly created example) is adding another object, you are expanding viable Your object can not be stored until the object handler is attached, along with the lifetime of your object, unless the object is attached.


Comments