public void AddTimer(string name, DateTime finishTime, Creature c, string group = "Custom")
        {
            TimerListEntry tle = new TimerListEntry
            {
                name     = name,
                group    = group,
                time     = finishTime,
                creature = c,
                sound    = SoundListBox.SelectedItem as string == DefaultSoundName
                        ? null : SoundListBox.SelectedItem as string,
                showInOverlay = Properties.Settings.Default.DisplayTimersInOverlayAutomatically
            };

            tle.lvi = CreateLvi(name, finishTime, tle);
            int i = 0;

            while (i < listViewTimer.Items.Count && ((TimerListEntry)listViewTimer.Items[i].Tag).time < finishTime)
            {
                i++;
            }
            listViewTimer.Items.Insert(i, tle.lvi);
            timerListEntries.Add(tle);
            OnTimerChange?.Invoke();
            RefreshOverlayTimers();
        }
 private void RemoveTimer(TimerListEntry timerEntry, bool invokeChange = true)
 {
     timerEntry.lvi.Remove();
     timerListEntries.Remove(timerEntry);
     if (invokeChange)
     {
         OnTimerChange?.Invoke();
     }
 }
Beispiel #3
0
        public void Stop()
        {
            if (_stopwatch == null)
            {
                return;
            }

            _cancelTokenSource.Cancel();
            Time = 0;
            _stopwatch.Reset();
            OnTimerChange?.Invoke();
        }
Beispiel #4
0
 private void SwTimer(int UdDatePeriud)
 {
     _stopwatch = Stopwatch.StartNew();
     while (true)
     {
         Time = _stopwatch.ElapsedMilliseconds;
         OnTimerChange?.Invoke();
         if (_token.IsCancellationRequested)
         {
             break;
         }
         Thread.Sleep(UdDatePeriud);
     }
 }
Beispiel #5
0
        public void SetTimer(string name, double durationSeconds)
        {
            TimerName     = name;
            TimerDuration = TimeSpan.FromSeconds(durationSeconds);

            Timer = new Timer((_) =>
            {
                TimerDuration = TimerDuration.Subtract(TimeSpan.FromSeconds(1));
                if (TimerDuration.TotalSeconds <= 0)
                {
                    Timer.Dispose();
                    Timer = null;
                }

                OnTimerChange?.Invoke();
            }, null, 0, 1000);
        }