ChatTimer( TimeSpan duration, [CanBeNull] string message, [NotNull] string startedBy ) {
if( startedBy == null ) throw new ArgumentNullException( "startedBy" );
StartedBy = startedBy;
Message = message;
StartTime = DateTime.UtcNow;
EndTime = StartTime.Add( duration );
Duration = duration;
int oneSecondRepeats = (int)duration.TotalSeconds + 1;
if( duration > Hour ) {
announceIntervalIndex = AnnounceIntervals.Length - 1;
lastHourAnnounced = (int)duration.TotalHours;
} else {
for( int i = 0; i < AnnounceIntervals.Length; i++ ) {
if( duration <= AnnounceIntervals[i] ) {
announceIntervalIndex = i - 1;
break;
}
}
}
task = Scheduler.NewTask( TimerCallback, this );
ID = Interlocked.Increment( ref timerCounter );
AddTimerToList( this );
IsRunning = true;
task.RunRepeating( TimeSpan.Zero,
TimeSpan.FromSeconds( 1 ),
oneSecondRepeats );
}