As soon as you stop hard-coding numbers passed to methods (that is, using
immediate constants), it will stop being a problem. Such matter-of-convenience problems are usually step from one or another kind of misuse. In real development, they don't even appear. Take the
Thread.Sleep
. It is rarely needed and often is a result of trying to synchronize things, which is simply false synchronization, this:
Race condition — Wikipedia, the free encyclopedia.
In legitimate cases, if can be just one value, but then it should rather be an explicitly defined constant. Please see the code sample below. Again,
Thread.Sleep
rarely makes sense, but it often makes sense in some software controlling external hardware. The the delay values should not be hard-coded even in constants, they should come from some data describing each device separately. And so on.
But the question is asked, I have to answer. One solution is Solution 1. Again, it's a matter of style. One approach could be:
const int min = 60000;
Thread.Sleep(2*min);
It won't allow you to enter fractions of a minute. Another obvious approach is defining your own
Sleep
method(s) accepting the parameters you want, anything you want. In its implementation, it should calculate milliseconds or an instance of
System.TimeSpan
and call
Thread.Sleep
.
—SA