修复设计模式下控件仍连接设备并更新图像的问题:在DeviceManager中为所有定时器和线程方法添加设计模式检查,优化Camera控件的设计模式状态更新逻辑
This commit is contained in:
@@ -48,6 +48,15 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
|
|
||||||
// 显示错误的定时器
|
// 显示错误的定时器
|
||||||
private System.Windows.Forms.Timer _errorDisplayTimer;
|
private System.Windows.Forms.Timer _errorDisplayTimer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新设计模式状态到DeviceManager
|
||||||
|
/// </summary>
|
||||||
|
private void UpdateDesignModeStatus()
|
||||||
|
{
|
||||||
|
DeviceManager.IsDesignMode = DesignMode;
|
||||||
|
Console.WriteLine($"相机控件设计模式状态已更新: {DesignMode}");
|
||||||
|
}
|
||||||
|
|
||||||
public Camera()
|
public Camera()
|
||||||
{
|
{
|
||||||
@@ -57,7 +66,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
this.contextMenuStrip1.Opening += ContextMenuStrip1_Opening;
|
this.contextMenuStrip1.Opening += ContextMenuStrip1_Opening;
|
||||||
|
|
||||||
// 将设计模式状态传递给DeviceManager
|
// 将设计模式状态传递给DeviceManager
|
||||||
DeviceManager.IsDesignMode = DesignMode;
|
UpdateDesignModeStatus();
|
||||||
|
|
||||||
// 只有在非设计模式下才初始化设备管理器和错误定时器
|
// 只有在非设计模式下才初始化设备管理器和错误定时器
|
||||||
if (!DesignMode)
|
if (!DesignMode)
|
||||||
|
|||||||
@@ -878,6 +878,13 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 在设计模式下,跳过实际的连接检查
|
||||||
|
if (IsDesignMode)
|
||||||
|
{
|
||||||
|
Log("设计模式下跳过实际的连接检查");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 首先停止现有的连接检查,确保资源释放
|
// 首先停止现有的连接检查,确保资源释放
|
||||||
StopConnectionCheck();
|
StopConnectionCheck();
|
||||||
|
|
||||||
@@ -1975,6 +1982,12 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void StartImageReconnect()
|
private void StartImageReconnect()
|
||||||
{
|
{
|
||||||
|
// 在设计模式下,跳过实际的图像重连
|
||||||
|
if (IsDesignMode)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 避免重复创建重连线程
|
// 避免重复创建重连线程
|
||||||
if (_imageReconnectThread != null && _imageReconnectThread.IsAlive)
|
if (_imageReconnectThread != null && _imageReconnectThread.IsAlive)
|
||||||
{
|
{
|
||||||
@@ -3358,6 +3371,13 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
{
|
{
|
||||||
Log($"[{DateTime.Now:HH:mm:ss.fff}] [线程:{Thread.CurrentThread.ManagedThreadId}] StartAutoReconnect() - 开始执行");
|
Log($"[{DateTime.Now:HH:mm:ss.fff}] [线程:{Thread.CurrentThread.ManagedThreadId}] StartAutoReconnect() - 开始执行");
|
||||||
|
|
||||||
|
// 在设计模式下,跳过实际的自动重连
|
||||||
|
if (IsDesignMode)
|
||||||
|
{
|
||||||
|
Log("设计模式下跳过实际的自动重连");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 检查对象是否已释放
|
// 检查对象是否已释放
|
||||||
if (_isDisposed)
|
if (_isDisposed)
|
||||||
{
|
{
|
||||||
@@ -3479,6 +3499,13 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// 在设计模式下,跳过实际的定期连接检查
|
||||||
|
if (IsDesignMode)
|
||||||
|
{
|
||||||
|
Log("设计模式下跳过实际的定期连接检查");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 停止现有的检查
|
// 停止现有的检查
|
||||||
StopConnectionCheck();
|
StopConnectionCheck();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user