From 1b51115e4e7fdf9259bb501c4b593b6c7818ef77 Mon Sep 17 00:00:00 2001 From: zqm Date: Wed, 29 Oct 2025 16:26:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E8=AE=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E6=8E=A7=E4=BB=B6=E4=BB=8D=E5=9C=A8=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E8=AE=BE=E5=A4=87=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E8=AE=BE=E8=AE=A1=E6=A8=A1=E5=BC=8F=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Camera.cs | 16 ++++++++-- .../Toprie/Toprie/DeviceManager.cs | 32 ++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index a8ed870..cfe5736 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -158,6 +158,7 @@ namespace JoyD.Windows.CS.Toprie /// public void StartCamera() { + if (DesignMode) return; try { // 只有在没有接收图像时才启动 @@ -244,6 +245,7 @@ namespace JoyD.Windows.CS.Toprie /// private void StartReceiveImage() { + if (DesignMode) return; try { if (!_isReceivingImage && _deviceManager.ConnectionStatus == ConnectionStatus.Connected) @@ -265,6 +267,7 @@ namespace JoyD.Windows.CS.Toprie /// public void StopCamera() { + if (DesignMode) return; try { if (_isReceivingImage) @@ -284,6 +287,7 @@ namespace JoyD.Windows.CS.Toprie /// private void DeviceManager_ImageReceived(object sender, ImageReceivedEventArgs e) { + if (DesignMode) return; Image image = null; try { @@ -449,6 +453,7 @@ namespace JoyD.Windows.CS.Toprie /// private void UpdateImageOnUI(Image image) { + if (DesignMode) return; // 线程安全检查 - 确保在UI线程上执行 if (this.InvokeRequired) { @@ -605,7 +610,8 @@ namespace JoyD.Windows.CS.Toprie /// 设备管理器连接状态变更事件处理 /// private void DeviceManager_ConnectionStatusChanged(object sender, ConnectionStatusChangedEventArgs e) - { + { + if (DesignMode) return; // 参数验证 if (e == null) { @@ -680,6 +686,7 @@ namespace JoyD.Windows.CS.Toprie /// private void HandleConnectionStatusChanged(ConnectionStatusChangedEventArgs e) { + if (DesignMode) return; try { // 确保在UI线程上更新UI状态 @@ -787,6 +794,7 @@ namespace JoyD.Windows.CS.Toprie /// 是否已连接 private void UpdateUIState(bool isConnected) { + if (DesignMode) return; try { // 根据连接状态更新图像框状态 @@ -829,7 +837,8 @@ namespace JoyD.Windows.CS.Toprie /// 设备管理器连接异常事件处理 /// private void DeviceManager_ConnectionException(object sender, ConnectionExceptionEventArgs e) - { + { + if (DesignMode) return; // 参数验证 if (e == null) { @@ -924,6 +933,7 @@ namespace JoyD.Windows.CS.Toprie /// private void ShowError(string message) { + if (DesignMode) return; Console.WriteLine(message); // 可以根据需要添加UI上的错误显示 @@ -968,6 +978,7 @@ namespace JoyD.Windows.CS.Toprie /// private void ErrorDisplayTimer_Tick(object sender, EventArgs e) { + if (DesignMode) return; _errorDisplayTimer.Stop(); // 清除错误显示,恢复到等待图像状态 @@ -1007,6 +1018,7 @@ namespace JoyD.Windows.CS.Toprie /// private void ContextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e) { + if (DesignMode) return; try { // 根据当前图像模式控制色彩模式菜单的可见性 diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs b/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs index 2ec9601..2f31099 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs @@ -151,7 +151,7 @@ namespace JoyD.Windows.CS.Toprie public class DeviceManager : IDisposable { // 设计模式标志,用于在设计模式下跳过实际的设备连接和初始化 - public static bool IsDesignMode { get; set; } = false; + public static bool IsDesignMode { get; set; } = true; // 项目路径,用于数据文件的存取 private string _projectPath = ""; @@ -1785,6 +1785,15 @@ namespace JoyD.Windows.CS.Toprie /// private void ReceiveImageDataWithHttpWebRequest() { + // 在设计模式下,跳过实际的图像接收 + if (IsDesignMode) + { + Log("设计模式下跳过实际的图像接收"); + // 设置为不接收状态,避免持续运行 + _isReceivingImages = false; + return; + } + Console.WriteLine($"图像接收线程启动: 使用HTTP请求获取图像数据"); try { @@ -2670,6 +2679,13 @@ namespace JoyD.Windows.CS.Toprie /// private void ReceiveImageThread() { + // 在设计模式下,跳过实际的图像接收 + if (IsDesignMode) + { + Log("设计模式下跳过实际的图像接收"); + return; + } + Console.WriteLine("警告: 已弃用的图像接收方式,使用HTTP方式替代"); try { @@ -3576,6 +3592,13 @@ namespace JoyD.Windows.CS.Toprie /// 定时器状态 private void ReconnectCallback(object state) { + // 在设计模式下,跳过实际的重连操作 + if (IsDesignMode) + { + Log("设计模式下跳过实际的重连操作"); + return; + } + Log($"[{DateTime.Now:HH:mm:ss.fff}] [线程:{Thread.CurrentThread.ManagedThreadId}] ReconnectCallback() - 开始执行"); // 使用Interlocked.Exchange实现原子操作检查,防止重入 @@ -3993,6 +4016,13 @@ namespace JoyD.Windows.CS.Toprie /// 定时器状态 private void HeartbeatCallback(object state) { + // 在设计模式下,跳过实际的心跳检测 + if (IsDesignMode) + { + Log("设计模式下跳过实际的心跳检测"); + return; + } + Log($"[{DateTime.Now:HH:mm:ss.fff}] [线程:{Thread.CurrentThread.ManagedThreadId}] HeartbeatCallback() - 开始执行"); // 检查对象是否已释放