Re: Threads and Timing
From: Daniel Moth (dmoth74_at_hotmail.com)
Date: 03/26/05
- Next message: Steve Maillet \(eMVP\): "Re: unloading programs in ROM"
- Previous message: Helen Warn: "Re: unloading programs in ROM"
- In reply to: Samer Saghir: "Re: Threads and Timing"
- Next in thread: Samer Saghir: "Re: Threads and Timing"
- Reply: Samer Saghir: "Re: Threads and Timing"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 26 Mar 2005 17:36:47 -0000
That is not my experience. Change(-1,-1) will stop the timer. BTW, -1 is
Infinite.
Make sure you are not starting any of the timers with a period other than -1
and in fact create them with -1,-1 (search constructors and all Change
methods).
Obviously, if the timer expires right at the moment you try to stop it then
it is too late. What interval are you using?
Also obvious, if you have started the timer with a period of -1 and it has
called you back, you don't have to stop it after it expires.
Maybe not so obvious, you should stop a timer as the first line/statement of
the TimerCallback handler and restart it if you need at the last line just
before the method exits.
You may also dispose a timer if you are not going to use it anymore...
If you still think Change(-1 doesn't stop your timer, post a small
reproducible sample...
Cheers
Daniel
-- http://www.danielmoth.com/Blog/ "Samer Saghir" <SamerSaghir@discussions.microsoft.com> wrote in message news:1C02FF9C-0A55-4CA4-ABFF-2DF402BB96E2@microsoft.com... > Daniel, > > I seem to be able to everything except stop the timer. I use > > timer.Change(Timeout.Infinite,Timeout.Infinite) > > but it isn't the solution. After a few trials it seems to be useful if the > period was being used because then if the Change() is applied the > TimerCallback won't be called again; but it doens't stop the timer. Is > there > something I can use to just stop the timer in it's tracks? > > Thanks > "Daniel Moth" wrote: > >> Just re-read my reply and it seems pretty clear. Have you got the code >> you >> are running now and I can show exactly which changes to make if that >> helps. >> Otherwise tell me which bit you don't understand... >> >> Cheers >> Daniel >> -- >> http://www.danielmoth.com/Blog/ >> >> >> "Samer Saghir" <SamerSaghir@discussions.microsoft.com> wrote in message >> news:A0F62844-1D9E-4DA1-93CB-363298E4E493@microsoft.com... >> >I posted this on the Windows CE Application Development newsgroup and >> >was >> > told to post it here: >> > >> >>Hey, >> >>I'm trying to get a peice of code to run repeatedly every X seconds and >> >>the whole >> >>thing shouldn't run for more than Y seconds. >> >> >> >>I tried using System.Threading.Timer and the period does the repeating >> >>forme >> >>but I have two problems: >> > >> >>1 - The period has nothing to do with whether the code has finished >> >>executing or >> >>not. So if the code requires 2 seconds to run and I specified a 1 sec >> >>repeat period >> >>it would run every second and not a second after the one before >> >>finished >> >>exceuting. (I've done some research and it seems that in regular .NET >> >>this >> >>can be >> >>solved by joining threads anything similar or workaround for .NETCF??) >> >> >> >>2 - I have to have a seperate thread running to moniter the overall >> >>time, >> >>can I >> >>avoid that? >> >> >> >>Thanks for the help >> >>Samer >> > >> >>>You should chain your timer events - do not use the period (use -1 >> >>>instead >> >>>for that parameter). I.e. when the timer expires, run your code and >> >>>start >> >>>the one-shot timer again with X. >> >>> >> >>>For your second requirement the easiest way is to have a separate >> >>>timer >> >>>running for Y. When it expires stop your first timer. >> >>> >> >>>The CF ng is best for CF questions: >> >>>microsoft.public.dotnet.framework.compactframework >> >>> >> >>>Cheers >> >>>Daniel >> >>>-- >> >>>http://www.danielmoth.com/Blog/ >> > >> > >> > I'm not sure I understand your suggestions....can you explain further a >> > bit? >> > Thanks >> > Samer >> > >> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- >> > Check out my blog at: >> > samersaghir.blogspot.com >> >>
- Next message: Steve Maillet \(eMVP\): "Re: unloading programs in ROM"
- Previous message: Helen Warn: "Re: unloading programs in ROM"
- In reply to: Samer Saghir: "Re: Threads and Timing"
- Next in thread: Samer Saghir: "Re: Threads and Timing"
- Reply: Samer Saghir: "Re: Threads and Timing"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|