using Microsoft.AspNetCore.Components; using PrintBarCode.Business; using PrintBarCode.Helper; using PrintBarCode.Model; using SlnMesnac.Redis; using static PrintBarCode.MessageClient; namespace PrintBarCode { public partial class MainForm : Form { public MainForm() { MessageClient.addLogEvent += addLog; InitializeComponent(); addLog("启动监听打印服务成功......"); } private void addLog(string logInfo) { try { // 如果当前调用线程不是创建窗体的线程,使用 Invoke if (this.logList.InvokeRequired) { this.logList.Invoke(new Action(addLog), logInfo); } else { this.logList.Items.Add($"{DateTime.Now}==>{logInfo}"); } } catch (Exception ex) { } } protected override void OnFormClosing(FormClosingEventArgs e) { // 取消关闭操作 e.Cancel = true; // 将窗口状态设置为最小化 this.WindowState = FormWindowState.Minimized; } } }