R
Rick
Hello,
Below I create a static instance of an object, works well.
public static BasicCounter GlobalCounter = new
BasicCounter("GlobalCounter");
private void Page_Load(object sender, System.EventArgs e)
{
GlobalCounter.Increment();
}
In BasicCounter the counts are stored in a Hashtable and I use the following
code to fire a method to store them in the database, once again all is
working well.
basicTimer.Elapsed += new ElapsedEventHandler(RecordCounter);
basicTimer.Interval = 60000;
basicTimer.Enabled = true;
In BasicCounter, I need to stop the timer when an instance of this object is
"unloaded". Meaning, when I recompile my page from VS.net, the counter
continues to fire and I don't want it to, this code seems to be working.
void Finalize()
{
/* Stop basicTimer, and then kill it */
basicTimer.Enabled = false;
basicTimer.Dispose();
}
Here's where it gets tricky, when I add these two method calls Finalize(),
they don't work, I even wait fifteen minutes for garbage collection to get
to it on localhost, still nothing:
// Write "Hello World" to a txt file..
// Call method that records Hashtable to DB method.
How can I be sure that if a static object instance is being unloaded, i.e.
page compile, that the current counts get recorded. Do objects have a built
in Application_End method?
Thank you in advance.
Rick
Below I create a static instance of an object, works well.
public static BasicCounter GlobalCounter = new
BasicCounter("GlobalCounter");
private void Page_Load(object sender, System.EventArgs e)
{
GlobalCounter.Increment();
}
In BasicCounter the counts are stored in a Hashtable and I use the following
code to fire a method to store them in the database, once again all is
working well.
basicTimer.Elapsed += new ElapsedEventHandler(RecordCounter);
basicTimer.Interval = 60000;
basicTimer.Enabled = true;
In BasicCounter, I need to stop the timer when an instance of this object is
"unloaded". Meaning, when I recompile my page from VS.net, the counter
continues to fire and I don't want it to, this code seems to be working.
void Finalize()
{
/* Stop basicTimer, and then kill it */
basicTimer.Enabled = false;
basicTimer.Dispose();
}
Here's where it gets tricky, when I add these two method calls Finalize(),
they don't work, I even wait fifteen minutes for garbage collection to get
to it on localhost, still nothing:
// Write "Hello World" to a txt file..
// Call method that records Hashtable to DB method.
How can I be sure that if a static object instance is being unloaded, i.e.
page compile, that the current counts get recorded. Do objects have a built
in Application_End method?
Thank you in advance.
Rick