示例#1
0
 private void Alarm(int secs, TimerData timerData)
 {
     Thread.Sleep(secs * 1000);
     if (!Entries.Contains(timerData))
     {
         return;
     }
     _context.API.ShowMsg("Timer ended", "", "Images\\icon.png");
     System.Media.SystemSounds.Beep.Play();
     Thread.Sleep(1000);
     System.Media.SystemSounds.Beep.Play();
     Thread.Sleep(1000);
     System.Media.SystemSounds.Beep.Play();
     Entries.Remove(timerData);
 }
示例#2
0
        private void Alarm(int secs, TimerData timerData)
        {
            Thread.Sleep(secs * 1000);

            lock (_lock)
            {
                if (!Entries.Contains(timerData))
                {
                    return;
                }
            }

            _context.API.ShowMsg("Timer ended", "", "Images\\icon.png");
            _alarmCompletionHandler.Complete();

            lock (_lock)
            {
                Entries.Remove(timerData);
            }
        }
示例#3
0
        private Result GetResult(int hours, int minutes, int seconds)
        {
            var sb = new StringBuilder();

            if (hours > 0)
            {
                sb.Append(" " + hours + " hour" + (hours > 1 ? "s" : ""));
            }
            if (minutes > 0)
            {
                sb.Append(" " + minutes + " minute" + (minutes > 1 ? "s" : ""));
            }
            if (seconds > 0)
            {
                sb.Append(" " + seconds + " second" + (seconds > 1 ? "s" : ""));
            }

            var formatted = sb.ToString().Substring(1);

            return(new Result
            {
                Title = "Timer",
                SubTitle = "Rings in " + formatted,
                IcoPath = "Images\\icon.png",
                Action = e =>
                {
                    var time = DateTime.Now + new TimeSpan(hours, minutes, seconds);
                    var timerData = new TimerData(time);
                    ThreadPool.QueueUserWorkItem(x => Alarm(hours * 3600 + minutes * 60 + seconds, timerData));
                    _context.API.ShowMsg("Timer Started", $"Timer will ring at {time:G}", "Images\\icon.png");
                    lock (_lock)
                    {
                        Entries.Add(timerData);
                    }

                    return true;
                }
            });
        }