void OnCollectionAdded(Collection collection) { Dispatcher.BeginInvoke((Action)(() => { if (collections.Any(c => c.Name == collection.Name)) { return; } collections.Add(new CollectionEditor(collection)); })); }
void OnItemAdded(Collection collection, CollectionItem item) { Dispatcher.BeginInvoke((Action)(() => { if (collection.Name != selectedcollection || items.Any(i => i.User == item.User && i.Item == item.Item)) { return; } items.Add(item); })); }
void OnPollAdded(Poll poll) { Dispatcher.BeginInvoke((Action)(() => { if (polls.Any(c => c.Name == poll.Name)) { return; } polls.Add(new PollEditor(poll)); })); }
void OnVoteAdded(PollVote vote) { Dispatcher.BeginInvoke((Action)(() => { if (vote.Poll != selectedpoll || votes.Any(i => i.User == vote.User && i.Vote == vote.Vote)) { return; } votes.Add(vote); })); }
void OnItemBlocked(Collection collection, BlockedCollectionItem item) { Dispatcher.BeginInvoke((Action)(() => { if (item.Collection != selectedcollection || blockeditems.Any(i => i.Item == item.Item)) { return; } blockeditems.RemoveWhere(i => i.Item == item.Item); blockeditems.Add(new BlockedItemEditor(item)); })); }
void OnOptionAdded(PollOption option) { Dispatcher.BeginInvoke((Action)(() => { if (option.Poll != selectedpoll || options.Any(i => i.Key == option.Key)) { return; } options.RemoveWhere(i => i.Key == option.Key); options.Add(new PollOptionEditor(option)); })); }
static void GetProcessesUsage() { UpdateProcessDataList(); TotalCpuTime = 0; TotalCpuLoadPct = TotalCpuLoadCounter.NextValue(); CurrentTime = DateTime.Now.Ticks.NextSecond(); lock (ProcessDataList) { lock (ProcessList) foreach (Process p in ProcessList) { var proc = ProcessDataList.Where(x => x.ID == p.Id).FirstOrDefault(); if (proc == null) { AddToProcessDataList(p); } else { if (!proc.IsProtected) { if (p.HasExited) { continue; } } proc.Time = CurrentTime; proc.ProcessorTimeDiff = p.TotalProcessorTime.Ticks - proc.ProcessorTime; TotalCpuTime += proc.ProcessorTimeDiff; proc.ProcessorTime = p.TotalProcessorTime.Ticks; } } foreach (ProcessData p in ProcessDataList) { if (p.ProcessorTimeDiff <= 0) { p.ProcessorLoadPercent = 0; } else { p.ProcessorLoadPercent = Math.Round(((p.ProcessorTimeDiff / (double)TotalCpuTime) * TotalCpuLoadPct), 2); if (p.ProcessorLoadPercent > 100) { p.ProcessorLoadPercent = 100; } if ((NotifyHighCpu || SuspendHighCpu) && p.ProcessorLoadPercent > ProcessorLoadThreshold && !CpuSuspendWhitelist.Any(x => x.Path == p.Path)) { if (SuspendHighCpu) { try { if (SuspendProcess(p.ID)) { ShowNotification(p.ID, p.Name, p.Path, ActionType.TerminateWhitelist); } } catch { } } else if (NotifyHighCpu) { if (!NotificationList.Any(x => x.NotActivated && x.Type == (int)ActionType.SuspendWhitelist && x.ApplicationPath == p.Path)) { ShowNotification(p.ID, p.Name, p.Path, ActionType.SuspendWhitelist); } } } } } } }