Question regarding timer.

A

archana

Hi all,

I am using timer to do some functionality on user specified time.

I am using system.timers.timer class and its timer to do this
functionality. What i am doing is i set autoreset to false as i want to
start processing only on user specified time.

I am setting interval as difference between user sepcified time and
current time. And when that elapsed event occured i am again setting
interval to new value with autoreset to false as i want to fire event
only once.

Means everytime i am reinitializing timer.

There is another solution and that is set autoreset to true and set
interval to say 1 min and in every min check current time with user
specified time. But this will cause timer to get fire every time.

so which one is better solution?

Can someone help me in deciding which i need to implement,

Any help will be truely appreciated.

Thanks in advance.
 
R

Rick Lones

archana said:
I am using system.timers.timer class and its timer to do this
functionality. What i am doing is i set autoreset to false as i want to
start processing only on user specified time.

I am setting interval as difference between user sepcified time and
current time. And when that elapsed event occured i am again setting
interval to new value with autoreset to false as i want to fire event
only once.

Means everytime i am reinitializing timer.

That doesn't sound especially hard or messy - so no problem with this approach.
The advantage is that the timer only fires when you have something to do.
There is another solution and that is set autoreset to true and set
interval to say 1 min and in every min check current time with user
specified time. But this will cause timer to get fire every time.

If one-minute granularity is good enough for your application then there is no
real problem with this approach either. The additional processing overhead is
insignificant. It may be slightly simpler to implement.
so which one is better solution?
Can someone help me in deciding which i need to implement,

Either one is fine - quit agonizing, just pick one and get on with it. I would
do it the first way, but only for esthetic (old fart) reasons.

HTH,
-rick-
 
A

archana

Hi, Rick

Thanks for your reply.
I was slight confuse regarding overheads in both approach.

But u cleared my confusion.

thanks a lot.
 
A

archana

Hi,

I have one more question regarding timer.

When timer's elapsed event is fire at that time in debug window i am
getting following msg
'The thread '<No Name>' (0x494) has exited with code 0 (0x0).'

can u tell me why this mesage is coming. This is not coming every time.

Thanks in advance.
 
K

Kevin Spencer

The message means that nothing bad happened when the thread exited. A return
value of 0 from a thread is an exception-less return.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
 
W

William Stacey [MVP]

I agree. I like the idea of manually controlling the set of the next event
incase I need to cancel or something. I makes me uneasy to have those
events going off every minute out-side my control. Method 1 also lets you
adjust for any minor drift, etc.

--
William Stacey [MVP]

| archana wrote:
| > I am using system.timers.timer class and its timer to do this
| > functionality. What i am doing is i set autoreset to false as i want to
| > start processing only on user specified time.
| >
| > I am setting interval as difference between user sepcified time and
| > current time. And when that elapsed event occured i am again setting
| > interval to new value with autoreset to false as i want to fire event
| > only once.
| >
| > Means everytime i am reinitializing timer.
|
| That doesn't sound especially hard or messy - so no problem with this
approach.
| The advantage is that the timer only fires when you have something to do.
|
| > There is another solution and that is set autoreset to true and set
| > interval to say 1 min and in every min check current time with user
| > specified time. But this will cause timer to get fire every time.
|
| If one-minute granularity is good enough for your application then there
is no
| real problem with this approach either. The additional processing
overhead is
| insignificant. It may be slightly simpler to implement.
|
| > so which one is better solution?
| > Can someone help me in deciding which i need to implement,
|
| Either one is fine - quit agonizing, just pick one and get on with it. I
would
| do it the first way, but only for esthetic (old fart) reasons.
|
| HTH,
| -rick-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top