System.Threading.Timer won't trigger
Posted
by mijatovic
on Stack Overflow
See other posts from Stack Overflow
or by mijatovic
Published on 2010-03-15T18:50:36Z
Indexed on
2010/03/15
18:59 UTC
Read the original article
Hit count: 155
Hello guys, I am new here...
I have one question, if somebody can help me.
It is about timers (System.Threading.Timer).
I want to break inevitable recursion: I have two columns in datarow and they are mutually dependant (price_without_VAT and price_with_VAT). Setting one of them will definitely cause StackOverflowException. So here's the idea:
bool flag = true;
void Reset(object state) { flag = true; }
Now, wrap the method for changing value of one of the columns:
{
if(flag)
{
flag = false;
System.Threading.Timer tmr = new System.Threading.Timer(new System.Threading.TimerCallback(Reset), null, 10, System.Threading.Timeout.Infinite);
datarow.other_column = value;
}
}
datarow.other_column.value line will immediately trigger the above method, but there will be no recursion because flag is false. In 10 ms flag should be back to true, and everything is back to normal.
Now, when i follow the code in DEBUGGER, everything works fine, but when I start app NORMALLY Reset function simply will not trigger, flag is stuck to false forever and everything false apart. I play around with due_time parameter but nothing seems to help.
Any ideas?
© Stack Overflow or respective owner