记录C#-WPF打开/关闭>>事件执行顺序

本文探讨了在编程中控制执行顺序的方法,这对于理解程序流程和优化性能至关重要。文章详细介绍了如何通过不同的编程构造和技术来管理代码的执行流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

                         打开执行顺序                                          关闭执行顺序

 

转载于:https://www.cnblogs.com/chenbingquan/p/10861053.html

using CommunityToolkit.Mvvm.ComponentModel; using Liudin.Acs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; namespace Liudin.App.ViewModels.bar { public partial class InfoBarViewModel : BaseViewModel { private readonly Singleton config; private readonly SynchronizationContext _syncContext; public InfoBarViewModel(Singleton _config) { config = _config; // 构造函数中捕获UI线程上下文 _syncContext = SynchronizationContext.Current ?? new SynchronizationContext(); ShowInfo(); } [ObservableProperty] private string infoText = "机器没有上电,请打开电源开关"; [ObservableProperty] private Brush? fontColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#006400")); /// <summary> /// 设置字体颜色 0-正常 1-警告 2-错误 /// </summary> /// <param name="lev"></param> private void SetMsgColor(int lev) { switch (lev) { case 0: FontColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#006400")); break; case 1: FontColor = Brushes.Orange; break; case 2: FontColor = Brushes.Red; break; } } private void ShowInfo() { try { Task.Run(async () => { while (config.IsUpdateInfo) { _syncContext.Post(_ => { InitInfo(); }, null); await Task.Delay(200); } }); } catch (TaskCanceledException) { /* 处理取消 */ } } private void InitInfo() { string msg = ""; if (JSGS.bPowerOn) { SetMsgColor(2); msg = "机器没有上电,请打开电源开关"; } else if (JSGS.bEStop) { SetMsgColor(2); msg = "急停开关已打开,处理好,关闭急停开关"; } else if (App.Current.m_bBgnHome) { SetMsgColor(1); msg = "机器启动,请回零"; } else if (JSGS.bToHome) { SetMsgColor(1); msg = "急停开关已关闭,请回零"; } else if (JSGS.bAlarm) { SetMsgColor(2); msg = "机器报警,请停止检查"; } else if (JSGS.bHoming) { SetMsgColor(1); msg = "机器正在回零..."; } else if (JLimit(ref msg)) { SetMsgColor(1); } else if (JSGS.bRunning) { SetMsgColor(0); msg = "系统正在自动运行中..."; } else { SetMsgColor(0); msg = "系统准备就绪,等待中..."; } } } } 优化该代码
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值