Exemplo n.º 1
0
        public static void TimingLoop()
        {
            while (true)
            {
                try
                {
                    Reminders.RemoveAll(r => r.GetSpan().TotalSeconds < 0.1);

                    if (Reminders.Any())
                    {
                        var nearest = Reminders.Min(r => r.GetSpan());
                        Console.WriteLine(nearest);
                        Added.BetterWaitOne(nearest);
                    }
                    else
                    {
                        Added.WaitOne();
                    }

                    Added.Reset();

                    var eligible = Reminders.Where(r => r.GetSpan().TotalSeconds < 2);

                    foreach (var reminder in eligible)
                    {
                        ReminderDone.Invoke(reminder);

                        SeenTracker[reminder] = new ManualResetEvent(false);
                        SeenTrackedNicks.Add(reminder.Nick);

                        Task.Factory.StartNew(delegate
                        {
                            if (!SeenTracker[reminder].WaitOne(Config.GetInt("remind.telldelay")))
                            {
                                TellManager.Tell("topkek_2000", reminder.Nick, string.Format("You asked to be reminded of \"{0}\" at {1}, but missed the reminder", reminder.Message, reminder.StartDate));
                            }

                            SeenTracker.Remove(reminder);
                            SeenTrackedNicks.Remove(reminder.Nick);
                        });
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
Exemplo n.º 2
0
 private void Storyboard_Completed(object sender, EventArgs e)
 {
     ReminderDone?.Invoke(this, EventArgs.Empty);
 }