private int NextTimeout (ArrayList timers, DateTime now) {
int timeout = 0;
foreach (Timer timer in timers) {
int next = (int) (timer.Expires - now).TotalMilliseconds;
if (next < 0) {
return 0; // Have a timer that has already expired
}
if (next < timeout) {
timeout = next;
}
}
if (timeout < Timer.Minimum) {
timeout = Timer.Minimum;
}
if (timeout > 1000)
timeout = 1000;
return timeout;
}