Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

phpmyadmin fehler rechte unerlaubte mischung, WWWXXXApc, lilo trying to map files from unnamed device 0x0000", Wwwxxxapc, CAM::PDF::Renderer::TextF Fragen, adodb.recordset error '800a0cc1', php save mails as eml, WWWXXXAPC, sqlexpress database file auto-creation error, sqlexpress database file auto-creation error

Links

XODOX
Impressum
Datenschutz

#1: Help: System.Threading.Timer doesn"t work!

Posted on 2008-04-23 16:54:06 by Fir5tSight

Hi,

In my code, I observe an event. In the event handler, I have:

if (mIsMarketOpen == false)
{
// Execute "CheckHistoricalData" every 15
seconds
System.Threading.Timer timer = new
Timer(CheckHistoricalData, null, 1000, 15000);
mIsMarketOpen = true;
}

But "CheckHistoricalData" method is never executed! Anyone can tell me
anything I did wrong? Thanks!

Report this message

#2: Re: Help: System.Threading.Timer doesn"t work!

Posted on 2008-04-23 19:06:20 by Jeroen Mostert

Curious wrote:
> In my code, I observe an event. In the event handler, I have:
>
> if (mIsMarketOpen == false)
> {
> // Execute "CheckHistoricalData" every 15
> seconds
> System.Threading.Timer timer = new
> Timer(CheckHistoricalData, null, 1000, 15000);
> mIsMarketOpen = true;
> }
>
> But "CheckHistoricalData" method is never executed! Anyone can tell me
> anything I did wrong? Thanks!

The timer goes out of scope at the end of the block and is hence eligible
for garbage collection. You'll want to move the timer reference and creation
to outside the event handler, for example:

private readonly Timer historicalDataTimer = new Timer(CheckHistoricalData);

Then in the event handler you can do:

historicalDataTimer.Change(1000, 15000);

--
J.
http://symbolsprose.blogspot.com

Report this message