public void AddLog(MsgLevel msgLog, string logInfo, Exception ex) { try { this.Invoke((MethodInvoker) delegate { listBox1.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " -> " + msgLog.ToString() + "," + logInfo + ex); listBox1.SelectedIndex = listBox1.Items.Count - 1; WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " -> " + msgLog.ToString() + "," + logInfo + ex); if (listBox1.Items.Count > 1000) { listBox1.Items.Clear(); } Application.DoEvents(); }); } catch (Exception) { } }
public void AddLog(MsgLevel msgLog, string logInfo) { try { this.Invoke((MethodInvoker) delegate { string recordMsg = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} -> {msgLog.ToString()}, {logInfo}"; listBox1.Items.Add(recordMsg); WriteLog(recordMsg); listBox1.SelectedIndex = listBox1.Items.Count - 1; if (listBox1.Items.Count > 1000) { listBox1.Items.Clear(); } Application.DoEvents(); }); } catch (Exception) { } }