ToDoTask.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. try
  31. {
  32. if (MainWindow.appData.ToDoList.Count > 0)
  33. {
  34. string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  35. ObservableCollection<ToDoInfo> exeBacklogList = MainWindow.appData.ToDoList;
  36. foreach (ToDoInfo info in exeBacklogList)
  37. {
  38. if (info.ExeTime.CompareTo(nowTime) == -1 && !activityBacklog.ContainsKey(info))
  39. {
  40. activityBacklog.Add(info, Notification.Show(new BacklogNotificatin(info), ShowAnimation.Fade, true));
  41. }
  42. }
  43. }
  44. }
  45. catch (Exception e1) { }
  46. //ClearMemory();
  47. }));
  48. }
  49. /// <summary>
  50. /// 释放内存
  51. /// </summary>
  52. public static void ClearMemory()
  53. {
  54. GC.Collect();
  55. GC.WaitForPendingFinalizers();
  56. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  57. {
  58. SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
  59. }
  60. }
  61. #region 内存回收
  62. [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
  63. public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
  64. #endregion
  65. }
  66. }