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()
[color=blue]
>-----Original Message-----
>OK. My suggestion would be to implement IDisposable, as[/color]
thats a clean way[color=blue]
>of telling the objects users that it can have resources[/color]
that require[color=blue]
>consideration. Likewise, I could not see where the void[/color]
Finalize code was[color=blue]
>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[/color]
the IDisposable[color=blue]
>Interface.
>
>Nick.
>"Rick" <nospan@nospam.com> wrote in message
>news:eMBMIOx0DHA.1760@TK2MSFTNGP10.phx.gbl...[color=green]
>> Sessions will not be used. The particularities of how[/color][/color]
to get this app to[color=blue][color=green]
>> work best aside, I'm most interested in how to do this[/color][/color]
type of clean up.[color=blue][color=green]
>>
>>
>> "Nick" <from@here.there> wrote in message
>> news:ONFbzWv0DHA.2868@TK2MSFTNGP09.phx.gbl...[color=darkred]
>> > Rick,
>> >
>> > Maybe you could consider a more simple design for[/color][/color][/color]
storing the counters.[color=blue][color=green][color=darkred]
>> > Could you record the counters in the DB when a[/color][/color][/color]
session ends?[color=blue][color=green][color=darkred]
>> >
>> > Nick.
>> >
>> > "Rick" <nospan@nospam.com> wrote in message
>> > news:e8akkNq0DHA.560@TK2MSFTNGP11.phx.gbl...
>> > > Hello,
>> > >
>> > > Below I create a static instance of an object,[/color][/color][/color]
works well.[color=blue][color=green][color=darkred]
>> > >
>> > > public static BasicCounter GlobalCounter = new
>> > > BasicCounter("GlobalCounter");
>> > >
>> > > private void Page_Load(object sender,[/color][/color][/color]
System.EventArgs e)[color=blue][color=green][color=darkred]
>> > > {
>> > > GlobalCounter.Increment();
>> > > }
>> > >
>> > > In BasicCounter the counts are stored in a[/color][/color][/color]
Hashtable and I use the[color=blue][color=green][color=darkred]
>> > following
>> > > code to fire a method to store them in the[/color][/color][/color]
database, once again all is[color=blue][color=green][color=darkred]
>> > > working well.
>> > >
>> > > basicTimer.Elapsed += new ElapsedEventHandler[/color][/color][/color]
(RecordCounter);[color=blue][color=green][color=darkred]
>> > > basicTimer.Interval = 60000;
>> > > basicTimer.Enabled = true;
>> > >
>> > >
>> > > In BasicCounter, I need to stop the timer when an[/color][/color][/color]
instance of this[color=blue][color=green]
>> object[color=darkred]
>> > is
>> > > "unloaded". Meaning, when I recompile my page from[/color][/color][/color]
VS.net, the counter[color=blue][color=green][color=darkred]
>> > > continues to fire and I don't want it to, this code[/color][/color][/color]
seems to be[color=blue]
>working.[color=green][color=darkred]
>> > > void Finalize()
>> > > {
>> > > /* Stop basicTimer, and then kill it */
>> > > basicTimer.Enabled = false;
>> > > basicTimer.Dispose();
>> > > }
>> > >
>> > > Here's where it gets tricky, when I add these two[/color][/color][/color]
method calls[color=blue][color=green]
>> Finalize(),[color=darkred]
>> > > they don't work, I even wait fifteen minutes for[/color][/color][/color]
garbage collection to[color=blue][color=green]
>> get[color=darkred]
>> > > 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[/color][/color][/color]
is being unloaded,[color=blue][color=green]
>> i.e.[color=darkred]
>> > > page compile, that the current counts get recorded.[/color][/color][/color]
Do objects have a[color=blue][color=green][color=darkred]
>> > built
>> > > in Application_End method?
>> > >
>> > > Thank you in advance.
>> > >
>> > > Rick
>> > >
>> > >
>> > >
>> > >
>> > >
>> > >
>> > >
>> > > ---
>> > > Outgoing mail is certified Virus Free.
>> > > Checked by AVG anti-virus system[/color][/color][/color]
(
http://www.grisoft.com).[color=blue][color=green][color=darkred]
>> > > Version: 6.0.552 / Virus Database: 344 - Release[/color][/color][/color]
Date: 12/15/2003[color=blue][color=green][color=darkred]
>> > >
>> > >
>> >
>> >[/color]
>>
>>
>> ---
>> Outgoing mail is certified Virus Free.
>> Checked by AVG anti-virus system[/color][/color]
(
http://www.grisoft.com).[color=blue][color=green]
>> Version: 6.0.558 / Virus Database: 350 - Release Date:[/color][/color]
1/2/2004[color=blue][color=green]
>>
>>[/color]
>
>
>.
>[/color]