Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Threading.Timer and TimeSpan
Message
 
To
25/03/2009 15:33:51
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Application:
Desktop
Miscellaneous
Thread ID:
01391484
Message ID:
01391904
Views:
41
Tim,
Would -1 help you?
See excerpt from M$ docs below
dueTime
Type: System..::.TimeSpan
A TimeSpan representing the amount of time to delay before invoking the callback method specified when the Timer was constructed. Specify negative one (-1) milliseconds to prevent the timer from restarting. Specify zero (0) to restart the timer immediately. 

period
Type: System..::.TimeSpan
The time interval between invocations of the callback method specified when the Timer was constructed. Specify negative one (-1) milliseconds to disable periodic signaling. 
>Hi All,
>
>I have a method I use to Set/ Reset my timers. I often need to set the first argument to infinity to stop the timer and then later set it back to a value to start it up again. My method creates a TimeSpan object to pass to the timer for both arguments of time. The below method works fine except when I pass in Infinite like this. I suppose a workaround is for me to pass in a really big value to create the TimeSpan with as the only reason I am stopping the timers is so I can do some processing before the timer fires again.
>
>
>// Call the set timer to stop it.  the TimeSpan seems to get created OK, but the timer.Change() fails because of the infinite value.
>this.SetTimer(tmrValidator, Timeout.Infinite, 60, null);
>
>private void SetTimer(System.Threading.Timer timer, int delaySeconds, int intervalSeconds, TimerCallback callback)
>{
>     TimeSpan delayTime = new TimeSpan(0, 0, delaySeconds);
>     TimeSpan intervalTime = new TimeSpan(0, 0, intervalSeconds);
>
>     if (timer == null)
>     {
>          using (AutoResetEvent autoEvent = new AutoResetEvent(true))
>          {
>					
>               if (callback == null)
>                    callback = new TimerCallback(this.OnBlankTimerEvent);
>
>               timer = new System.Threading.Timer(callback, autoEvent,
>               delayTime, intervalTime);
>          }
>     }
>     else // Reset Timer
>     {
>          timer.Change(delayTime, intervalTime);
>     }
>}
>
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform