ToDoTask.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using GeekDesk.Control.Other;
  2. using GeekDesk.ViewModel;
  3. using HandyControl.Controls;
  4. using HandyControl.Data;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Runtime.InteropServices;
  9. using System.Timers;
  10. namespace GeekDesk.Task
  11. {
  12. public class ToDoTask
  13. {
  14. ///public static ObservableCollection<ToDoInfo> activityBacklog = new ObservableCollection<ToDoInfo>();
  15. public static Dictionary<ToDoInfo, Notification> activityBacklog = new Dictionary<ToDoInfo, Notification>();
  16. public static void BackLogCheck()
  17. {
  18. System.Timers.Timer timer = new System.Timers.Timer
  19. {
  20. Enabled = true,
  21. Interval = 5000
  22. };
  23. timer.Start();
  24. timer.Elapsed += new System.Timers.ElapsedEventHandler(Check);
  25. }
  26. private static void Check(object source, ElapsedEventArgs e)
  27. {
  28. App.Current.Dispatcher.Invoke((Action)(() =>
  29. {
  30. if (MainWindow.appData.ToDoList.Count > 0)
  31. {
  32. string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  33. ObservableCollection<ToDoInfo> exeBacklogList = MainWindow.appData.ToDoList;
  34. foreach (ToDoInfo info in exeBacklogList)
  35. {
  36. if (info.ExeTime.CompareTo(nowTime) == -1 && !activityBacklog.ContainsKey(info))
  37. {
  38. activityBacklog.Add(info, Notification.Show(new BacklogNotificatin(info), ShowAnimation.Fade, true));
  39. }
  40. }
  41. }
  42. //ClearMemory();
  43. }));
  44. }
  45. /// <summary>
  46. /// 释放内存
  47. /// </summary>
  48. public static void ClearMemory()
  49. {
  50. GC.Collect();
  51. GC.WaitForPendingFinalizers();
  52. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  53. {
  54. SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
  55. }
  56. }
  57. #region 内存回收
  58. [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
  59. public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
  60. #endregion
  61. }
  62. }