diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index deab202..201dad5 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -213,6 +213,92 @@ namespace JoyD.Windows.CS.Toprie } } + /// + /// 关闭相机并完全释放所有资源 + /// + [Category("控制")] + [DisplayName("关闭相机")] + [Description("关闭相机并完全释放所有资源")] + public void Close() + { + try + { + // 停止相机并释放相关资源 + StopCamera(); + + // 关闭设置窗口 + Setting.Form.Close(); + + // 取消注册事件并释放设备管理器 + if (_deviceManager != null) + { + // 移除所有事件监听 + _deviceManager.ImageReceived -= DeviceManager_ImageReceived; + _deviceManager.ConnectionStatusChanged -= DeviceManager_ConnectionStatusChanged; + _deviceManager.ConnectionException -= DeviceManager_ConnectionException; + + // 释放设备管理器资源 + _deviceManager.Dispose(); + _deviceManager = null; + } + + // 释放Ping定时器 + if (_pingTimer != null) + { + _pingTimer.Dispose(); + _pingTimer = null; + } + + // 释放图像控件资源 + if (imageBox != null && !imageBox.IsDisposed && imageBox.Image != null) + { + imageBox.Image.Dispose(); + imageBox.Image = null; + } + + // 释放图像缓冲区资源 + if (_imageBuffer != null) + { + _imageBuffer.Dispose(); + _imageBuffer = null; + } + + // 释放LastImage资源 + lock (_lastImageLock) + { + if (_lastImage != null) + { + _lastImage.Dispose(); + _lastImage = null; + } + } + + // 释放InfoImage资源 + lock (_infoImageLock) + { + if (_infoImage != null) + { + _infoImage.Dispose(); + _infoImage = null; + } + } + + // 释放DisplayImage资源 + lock (_displayImageLock) + { + if (_displayImage != null) + { + _displayImage.Dispose(); + _displayImage = null; + } + } + } + catch (Exception ex) + { + Console.WriteLine($"关闭相机时出错: {ex.Message}"); + } + } + /// /// 获取指定测温区的温度值 /// diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Properties/AssemblyInfo.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Properties/AssemblyInfo.cs index a81c154..a13f9cf 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Properties/AssemblyInfo.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Properties/AssemblyInfo.cs @@ -33,6 +33,6 @@ using System.Runtime.InteropServices; //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.2.0")] -[assembly: AssemblyFileVersion("1.0.2.3")] +[assembly: AssemblyFileVersion("1.0.2.4")] // NuGet包相关信息已在项目文件中配置