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
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.552 / Virus Database: 344 - Release Date: 12/15/2003 4 1786
Rick,
Maybe you could consider a more simple design for storing the counters.
Could you record the counters in the DB when a session ends?
Nick.
"Rick" <no****@nospam.com> wrote in message
news:e8*************@TK2MSFTNGP11.phx.gbl... 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
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.552 / Virus Database: 344 - Release Date: 12/15/2003
Sessions will not be used. The particularities of how to get this app to
work best aside, I'm most interested in how to do this type of clean up.
"Nick" <fr**@here.there> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl... Rick,
Maybe you could consider a more simple design for storing the counters. Could you record the counters in the DB when a session ends?
Nick.
"Rick" <no****@nospam.com> wrote in message news:e8*************@TK2MSFTNGP11.phx.gbl... 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
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.552 / Virus Database: 344 - Release Date: 12/15/2003
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.558 / Virus Database: 350 - Release Date: 1/2/2004
OK. My suggestion would be to implement IDisposable, as thats a clean way
of telling the objects users that it can have resources that require
consideration. Likewise, I could not see where the void Finalize code was
being invoked from. An object defines a destructor as:
public class Foo
{
public Foo(/* constructor */)
{
}
~Foo()
{
}
}
But I wouldnt put my code in the destructor, I would use the IDisposable
Interface.
Nick.
"Rick" <no****@nospam.com> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl... Sessions will not be used. The particularities of how to get this app to work best aside, I'm most interested in how to do this type of clean up.
"Nick" <fr**@here.there> wrote in message news:ON**************@TK2MSFTNGP09.phx.gbl... Rick,
Maybe you could consider a more simple design for storing the counters. Could you record the counters in the DB when a session ends?
Nick.
"Rick" <no****@nospam.com> wrote in message news:e8*************@TK2MSFTNGP11.phx.gbl... 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
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.552 / Virus Database: 344 - Release Date: 12/15/2003
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.558 / Virus Database: 350 - Release Date: 1/2/2004
Hi Rick,
I believe Nick's suggestion to implement the IDisposable
interface to have deterministic finalization is the best
approach. I can forward you a generic way to apply this to
all of your objects.
An important note to remember here is that if you supply a
destructor in C#, the compiler emits a Finalize method.
The garbage collector promotes all objects (that it
considers garbage) that expose a Finalize method to a
finalization list during the first pass of garbage
collection. Therefore, your object is, in a sense,
ressurected upon first pass so that the framework can call
the finalize method on it. This could be why your object
is not completely dead.
Anyway... with all that said, you may want to implement
IDisposable and in the Dispose() method call
GC.SuppressFinalization() after stopping the time which
will immediately release all resources and release the
memory consumed by your object-your object will essetially
be dead at this point.
Hope this helps.
-IDoNothing.Go() -----Original Message----- OK. My suggestion would be to implement IDisposable, as
thats a clean wayof telling the objects users that it can have resources
that requireconsideration. Likewise, I could not see where the void
Finalize code wasbeing invoked from. An object defines a destructor as:
public class Foo { public Foo(/* constructor */) { }
~Foo() { } }
But I wouldnt put my code in the destructor, I would use
the IDisposableInterface.
Nick. "Rick" <no****@nospam.com> wrote in message news:eM**************@TK2MSFTNGP10.phx.gbl... Sessions will not be used. The particularities of how
to get this app to work best aside, I'm most interested in how to do this
type of clean up.
"Nick" <fr**@here.there> wrote in message news:ON**************@TK2MSFTNGP09.phx.gbl... > Rick, > > Maybe you could consider a more simple design for
storing the counters. > Could you record the counters in the DB when a
session ends? > > Nick. > > "Rick" <no****@nospam.com> wrote in message > news:e8*************@TK2MSFTNGP11.phx.gbl... > > 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 beworking. > > 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 > > > > > > > > > > > > > > > > --- > > Outgoing mail is certified Virus Free. > > Checked by AVG anti-virus system
(http://www.grisoft.com). > > Version: 6.0.552 / Virus Database: 344 - Release
Date: 12/15/2003 > > > > > >
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system
(http://www.grisoft.com). Version: 6.0.558 / Virus Database: 350 - Release Date:
1/2/2004
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike |
last post by:
Please help this is driving me nuts. I have 2 forms, 1 user class and I am
trying to implement a singleton class. Form 1 should create a user object
and populate some properties in user. Form2...
|
by: Chris Capel |
last post by:
What is the rationale behind the decision not to allow abstract static class
members? It doesn't seem like it's a logically contradictory concept, or
that the implementation would be difficult or...
|
by: MyNameIsnt |
last post by:
Can anyone tell me why, when I click on the buttons it register 2
characters on the display?
if you use the right mousebutton it works ok, but the buttons dont
flash??
it works fine without the...
|
by: john |
last post by:
Hi,All MS Tech Gurus:
I need your help!!! It is the second time I post this message, I need get
some feedback ASAP, Please Help!!
Thanks a lot in advance.
John
I have a csharp method, using...
|
by: Doruk |
last post by:
The problem that we are experiencing is simple:
We want to pass certain parameters from a page with several server
controls to another page.
We want to do this in a dotnet compliant manner,...
|
by: Sky Sigal |
last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols)
I've been looking lately for a way to keep the Properties panel for Controls
'clean'...
My goal is to keep similar...
|
by: Joe Narissi |
last post by:
I know how to create and use static constructors, but is there a such thing
as a static destructor?
If not, then how do you deallocate memory intialized in the static
constructor?
Thanks in...
|
by: Bryan Kyle |
last post by:
Hi All,
I'm fairly new to C# and Generics and I'm wondering if anyone has some
suggestions for me.
I'm trying to implement a simple DAO framework using generics to keep
my code as clean as I...
|
by: TC |
last post by:
Hey All,
I have some classes that I recently built for a website which uses the
HttpWebRequest & HttpWebResponse objects from the System.Net namespace.
Basically, the classes rap submitted data...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |