Re: Threads and garbage collection
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/09/04
- Next message: kk: "Re: Threads and garbage collection"
- Previous message: kk: "Re: Threads and garbage collection"
- In reply to: kk: "Re: Threads and garbage collection"
- Next in thread: kk: "Re: Threads and garbage collection"
- Reply: kk: "Re: Threads and garbage collection"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 9 Jun 2004 15:18:52 +0100
kk <anonymous@discussions.microsoft.com> wrote:
> You wont be a able to compile this, but hopefullty it will explain
> more clearly what I'm doing.
> The constructor FrmNetPositions, is responsible for calling the
> methos which referneces the api calls, opeing certain objects and
> setting event hadlers with these objects. These call backs are firing
> fine until what I presume is the garbage collector kicks in. This all
> happens on the main UI thread. The timer is a system timer and
> therefore is on a second thread. This continues to tick along fine
> after the gc collects.
> Thanks in advance.
> Sorry the code is not runnable but without the third party s/w anyway....?
Why don't you make it runnable then? I *strongly* recommend that you
create a test framework which I *can* compile and run, and which just
has Thread.Sleep calls where you would normally be doing some work.
I also strongly suggest that rather than calling Monitor.Enter/Exit
directly, you use the lock statement. (Unfortunately there's no
equivalent for TryEnter, so you'll still need that.)
GC.KeepAlive is pointless with Thread references. The Thread references
won't be reachable until the thread has terminated.
You're also unconditionally calling Monitor.Exit(tempCache.SyncRoot)
and Monitor.Exit(this.calcLock) whether or not you managed to acquire
those locks.
In short, it's all still very confused, with lots of locks which aren't
explained, an IAsyncResult which is set but never used (as far as I can
see) - and no runnable code.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: kk: "Re: Threads and garbage collection"
- Previous message: kk: "Re: Threads and garbage collection"
- In reply to: kk: "Re: Threads and garbage collection"
- Next in thread: kk: "Re: Threads and garbage collection"
- Reply: kk: "Re: Threads and garbage collection"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|