private static void ThreadingTimerCallback(object state) { postManager.Client.UpdateCredentials(); if ((++triggerCount) == 360) { triggerCount = 0; today = DateTime.Today; var newJobList = new DailyJobList(); //var files = new DirectoryInfo(configText[0]).GetFiles(); foreach (var f in Directory.EnumerateFiles(configText[0])) { newJobList.Add(DailyJob.Deserialize(File.ReadAllText(f))); } dailyJobList = newJobList; GC.Collect(); } var now = DateTime.Now; var removeList = new List <Reminder>(); foreach (var remind in remindList) { if (remind.PostTime < now) { postManager.Col.Add(remind.Post); remind.Posted = true; removeList.Add(remind); } } foreach (var rm in removeList) { remindList.Remove(rm); Console.WriteLine(remindList.Count); } }
static void Main(string[] args) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; if (dailyJobList == null) { today = DateTime.Today; dailyJobList = new DailyJobList(); //var files = new DirectoryInfo(configText[0]).GetFiles(); foreach (var f in Directory.EnumerateFiles(configText[0])) { var tmp = File.ReadAllText(f); dailyJobList.Add(DailyJob.Deserialize(tmp)); } } if (File.Exists("remindList.json")) { remindList = new RemindList(Reminder.Deserialize(File.ReadAllText("remindList.json"))); } if (File.Exists("feedList.json")) { feedList.AddRange(File.ReadLines("feedList.json").Select(x => long.Parse(x)).ToList()); } var timer = new Timer(new TimerCallback(ThreadingTimerCallback)); timer.Change(0, 1000 * 10); postManager.Col.CollectionChanged += (sender, e) => { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { var c = e.NewItems.Count; var item = postManager.Col.Select(x => x).ToArray(); foreach (var x in item) { postManager.Col.Remove(x); Console.WriteLine(x.Content); postManager.Client.PostStatus(x.Content, x.Visibility, replyStatusId: x.Id, sensitive: x.Sensitive, spoilerText: x.Spoiler); Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); } Debug.WriteLine(item.First().Content); } }; remindList.CollectionChanged += (sender, e) => { var jsonString = string.Join(",\n", remindList.Select(x => x.Serialize())); File.WriteAllText("remindList.json", $"[{jsonString}]"); }; var task = RunAsync(); task.Wait(); }