Re: Threads and garbage collection

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/09/04


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


Relevant Pages

  • Re: Network stack locking question
    ... I suggest is that you *do not* hold any locks when calling ether_demuxfor whatever reason. ... When re-entering the bottom of the stack in this way, you *should not* hold any locks. ... rtalloc_igncurrently acquires a lock on its rtentry by default, please release it before reentering the bottom half of the network stack. ...
    (freebsd-net)
  • Re: Network stack locking question
    ... I suggest is that you *do not* hold any locks when calling ether_demux ... When re-entering the bottom of the stack in this way, ... network stack. ...
    (freebsd-net)
  • Re: return from main
    ... undertand the following lines (mentioned in n1124.pdf at page 13. ... int, a return from the ... The start-up code performs whatever processing is needed prior to calling main, such as setting up the argv array. ... However, recursive calls to mainare such a bizarre thing to do that you ordinarily wouldn't have any reason to use them, particular if you want to compile the same code in C++, where they are not allowed. ...
    (comp.lang.c)
  • Thanks : Re: How to get Code Segment Base Address in PM
    ... (there is a intruction reading eip on the x86:) ... and compile it with nasmw.exe myfile.asm -o myfileout.bin ... Then I copy that output of the NASM compiler in a string in the upper level language and call that assembler code by calling ...
    (comp.lang.asm.x86)
  • Re: gawk for windows: system() does not yield exit status
    ... *OR* my versions of gawk is calling an old command.com by default (which ... Ruby or Perl without problems. ... If you have a version of GAWK-for-Windows ... compiler/toolchain/library used in the compile. ...
    (comp.lang.awk)