private static void UpdateCallback() { if (_Updating || !Connection.Connected) { return; } _Updating = true; LastUpdate = DateTime.Now; Connection.NonQuery( @"CREATE DATABASE IF NOT EXISTS `{0}` DEFAULT CHARSET `utf8` DEFAULT COLLATE `utf8_bin`", CMOptions.MySQL.Database); Connection.UseDatabase(CMOptions.MySQL.Database); var watch = new Stopwatch(); watch.Start(); VitaNexCore.TryCatch( () => { Process(); Flush(); }, x => { CMOptions.ToConsole(x); OnAbort(); }); watch.Stop(); CMOptions.ToConsole("Updated {0:#,0} objects in {1:F2} seconds.", _UpdateCount, watch.Elapsed.TotalSeconds); if (UpdateTimes.Count >= 10) { UpdateTimes.Dequeue(); } UpdateTimes.Enqueue(watch.Elapsed); ExportQueue.Clear(); if (_Connection != null) { _Connection.Close(); _Connection = null; } //GC.Collect(); _UpdateCount = 0; _Updating = false; }
private void DispatcherTimerAction(Object sender, EventArgs e) { if (!File.Exists(@"D:\Maintain.csv")) { string[] heads = { "时间", "机台号", "触发次数", "扫码次数", "上传次数" }; Csvfile.AddNewLine(@"D:\Maintain.csv", heads); } if (LastCleanRecordFlag != GetBanciDate() + GetBanci()) { LastCleanRecordFlag = GetBanciDate() + GetBanci(); Inifile.INIWriteValue(ParameterIniPath, "Record", "LastCleanRecordFlag", LastCleanRecordFlag); if (!Directory.Exists("D:\\" + LastCleanRecordFlag)) { Directory.CreateDirectory("D:\\" + LastCleanRecordFlag); } string[] count = { DateTime.Now.ToString(), JiTaiHao, TrigerTimes.ToString(), ScanTimes.ToString(), UpdateTimes.ToString() }; Csvfile.AddNewLine(@"D:\Maintain.csv", count); TrigerTimes = 0; ScanTimes = 0; UpdateTimes = 0; Inifile.INIWriteValue(ParameterIniPath, "Times", "TrigerTimes", TrigerTimes.ToString()); Inifile.INIWriteValue(ParameterIniPath, "Times", "ScanTimes", ScanTimes.ToString()); Inifile.INIWriteValue(ParameterIniPath, "Times", "UpdateTimes", UpdateTimes.ToString()); MsgText = AddMessage("记录清空"); } if (recordItemList.Count > 0) { lock (LockObject) { foreach (RecordItem item in recordItemList) { RecordCollection.Add(item); } recordItemList.Clear(); } } }