public NotifyMessageController(double screenWidth, double screenHeight, double popupWidth, double popupHeight) { MaxPopup = Convert.ToInt32(screenHeight / popupHeight) - 1; DisplayLocations = new List<AnimatedLocation>(MaxPopup); DisplayMessages = new NotifyMessageViewModel[MaxPopup]; QueuedMessages = new ConcurrentQueue<NotifyMessage>(); double left = screenWidth - popupWidth; double top = screenHeight; for (int i = 0; i < MaxPopup; i++) { if (i == 0) { DisplayLocations.Add(new AnimatedLocation(left, left, screenHeight, top - popupHeight)); } else { var previousLocation = DisplayLocations[i - 1]; DisplayLocations.Add(new AnimatedLocation(left, left, previousLocation.ToTop, previousLocation.ToTop - popupHeight)); } } this.isStarted = false; }
private Task StartService(CancellationToken cancellationToken) { var dispatcher = Application.Current.MainWindow.Dispatcher; return Task.Factory.StartNew(() => { do { int nextlocation = FindNextLocation(); if (nextlocation > -1) { NotifyMessage msg = null; if (QueuedMessages.TryDequeue(out msg)) { var viewModel = new NotifyMessageViewModel(msg, DisplayLocations[nextlocation], () => DisplayMessages[nextlocation] = null); DisplayMessages[nextlocation] = viewModel; dispatcher.BeginInvoke( new MethodInvoker(() => { var window = new NotifyMessageWindow() { Owner = Application.Current.MainWindow, DataContext = viewModel, ShowInTaskbar = false }; window.Show(); }), DispatcherPriority.Background); } } Thread.Sleep(1000); } while (QueuedMessages.Count > 0 && !cancellationToken.IsCancellationRequested); Stop(); }); }