System.Threading.Timer improper function in Release mode

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

From: Hagay Lupesko (hagayl_at_nice.com)
Date: 05/11/04


Date: Tue, 11 May 2004 11:51:21 +0300

Hi,

I've encountered a strange phenomena which appears to me as a bug:

I have an engine that uses a System.Threading.Timer to invoke a delegate
every X minutes.

The code looks something like this:
TimerCallback callBack = new TimerCallback(Run); // run is obviously a
method
analysisTimer = new Timer(callBack, null, 0, delay);
Console.ReadLine();

Everything works just fine when the code is build in Debug mode, but when
the code is build in Release mode the delegate is invoked once only.

After creating debug symbols for the Release mode it looks like the timer
class is optimized away...

The workaround solution I used was declaring the timer as static.

But obviously it's not very nice...

Any clue as to is this a bug, or what's wrong with the code ?

Thanks, Hagay.



Relevant Pages

  • Re: System.Threading.Timer improper function in Release mode
    ... > I have an engine that uses a System.Threading.Timer to invoke a delegate ... > Everything works just fine when the code is build in Debug mode, ... > the code is build in Release mode the delegate is invoked once only. ... > The workaround solution I used was declaring the timer as static. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: MissingMethodException with MulticastDelegate
    ... You are hitting a bug in .NETCF v1 on ARM-compatible devices. ... delegates and invoke each one separately. ... This bug does not exist in any of the pre-release versions of .NETCF v2. ... >delegate) I can catch the exception. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Control.BeginInvoke is NOT fire-and-forget
    ... Do you think this is a CLR bug or it is by design? ... concise-but-complete code sample that reliably demonstrates the ... helper.postProcessing = delegate; ... of the worker threadproc from BeginInvoke to Invoke does cure the problem. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threading issue -- with no threads?!?
    ... When you call the event (i.e. delegate) in your timer ... | Where I'm confused is in the fact that my engine object is what contains ... |> finishes but you don't need to worry about Invoke. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Problem calling Invoke to call a delegate on a child thread
    ... Timer on the main thread (which only gets activated after the child threads ... For each job found this timer invokes a delegate on one of the child thread ... I then get the error "Cannot call Invoke or InvokeAsync on a control until ...
    (microsoft.public.dotnet.languages.csharp)