Files
GeekDesk/Task/ToDoTask.cs

74 lines
2.3 KiB
C#
Raw Normal View History

using GeekDesk.Control.Other;
using GeekDesk.ViewModel;
using HandyControl.Controls;
using HandyControl.Data;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
2021-08-20 16:49:20 +08:00
using System.Runtime.InteropServices;
2021-06-17 23:06:46 +08:00
using System.Timers;
namespace GeekDesk.Task
{
public class ToDoTask
{
2021-06-17 23:06:46 +08:00
///public static ObservableCollection<ToDoInfo> activityBacklog = new ObservableCollection<ToDoInfo>();
2021-06-17 23:06:46 +08:00
public static Dictionary<ToDoInfo, Notification> activityBacklog = new Dictionary<ToDoInfo, Notification>();
2021-06-17 23:06:46 +08:00
public static void BackLogCheck()
{
2021-08-20 16:49:20 +08:00
System.Timers.Timer timer = new System.Timers.Timer
{
Enabled = true,
Interval = 5000
};
2021-06-17 23:06:46 +08:00
timer.Start();
timer.Elapsed += new System.Timers.ElapsedEventHandler(Check);
}
private static void Check(object source, ElapsedEventArgs e)
{
2021-06-17 23:06:46 +08:00
App.Current.Dispatcher.Invoke((Action)(() =>
{
if (MainWindow.appData.ToDoList.Count > 0)
{
2021-06-17 23:06:46 +08:00
string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
ObservableCollection<ToDoInfo> exeBacklogList = MainWindow.appData.ToDoList;
foreach (ToDoInfo info in exeBacklogList)
{
2021-06-17 23:06:46 +08:00
if (info.ExeTime.CompareTo(nowTime) == -1 && !activityBacklog.ContainsKey(info))
{
activityBacklog.Add(info, Notification.Show(new BacklogNotificatin(info), ShowAnimation.Fade, true));
}
}
}
2021-08-20 16:49:20 +08:00
ClearMemory();
2021-06-17 23:06:46 +08:00
}));
}
2021-08-20 16:49:20 +08:00
/// <summary>
/// 释放内存
/// </summary>
public static void ClearMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
2022-06-07 11:16:14 +08:00
}
2021-08-20 16:49:20 +08:00
}
#region
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
#endregion
2021-06-17 23:06:46 +08:00
}
}