views:

42

answers:

2

I have a method that links a BO Connection.AliveInterval to a System.Timers.Timer (.NET 2).

Some connections are managed to be always connected.

Is it OK to set in such a case

if (myConnection.AliveInterval == Connection.TimeInfinite)
{
    myTimer.Interval = double.PositiveInfinity;
}

?

Should I expect that the Timer will throw exceptions or rises ever the Elapsed event ?

A: 

Why not myTimer.Stop()?

spender
because this is not an action, but an initialization. And I didn't Start()
serhio
`myTimer.Enabled=false` ?
Bolu
Downvote seems a little stern.
spender
@Bolu. Maybe... however, what about the `Interval`?
serhio
In the context of your question that is lacking in the necessary information to offer better informed help, I think it is probably your style of question that is not useful. You're burning your bridges by such arrogant behaviour. If I'd picked up this question and had a chance to observe your "community spirit", I wouldn't bother answering.
spender
based on MSDN:The value must be greater than zero, and less than or equal to Int32.MaxValue.
Bolu
To quote MSDN: "Setting Enabled to true is the same as calling Start, while setting Enabled to false is the same as calling Stop.". Your response to @Bolu is inconsistent with your response to me.
spender
@spender: Once Connected, the timer.`Start` (or Enabled=true) will be called. So, there is no sense to set enabled to false(or Stop).
serhio
+1  A: 

MSDN:

The value must be greater than zero, and less than or equal to Int32.MaxValue

An ArgumentException will be thrown, when the interval is greater than Int32.MaxValue, and the timer is currently enabled. If the timer is not currently enabled, no exception is thrown until it becomes enabled.

So, the PositiveInfinity will throw an exception, if the simer will be enabled.

Now, a solution would be to disable the timer and set the value to PositiveInfinity. When Enabling the Timer, catch ArgumentException and ceck the Interval to PositiveInfinity.

moldovanu