修复代码规范警告:1. 将imageBox_DoubleClick方法名修改为符合命名规则的ImageBox_DoubleClick 2. 简化Setting.cs中Timer对象的初始化
This commit is contained in:
@@ -58,7 +58,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
this.imageBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
this.imageBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||||
this.imageBox.TabIndex = 0;
|
this.imageBox.TabIndex = 0;
|
||||||
this.imageBox.TabStop = false;
|
this.imageBox.TabStop = false;
|
||||||
this.imageBox.DoubleClick += new System.EventHandler(this.imageBox_DoubleClick);
|
this.imageBox.DoubleClick += new System.EventHandler(this.ImageBox_DoubleClick);
|
||||||
//
|
//
|
||||||
// contextMenuStrip1
|
// contextMenuStrip1
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -828,7 +828,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
// 创建图像副本以避免线程安全问题
|
// 创建图像副本以避免线程安全问题
|
||||||
Image clonedImage = (Image)tempImage.Clone();
|
Image clonedImage = (Image)tempImage.Clone();
|
||||||
// 调用Setting窗口的方法更新实时温度图像
|
// 调用Setting窗口的方法更新实时温度图像
|
||||||
Setting.Form.UpdateRealTimeTemperatureImage(clonedImage);
|
Setting.Form.RealTimeImage = clonedImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastImage != null)
|
if (lastImage != null)
|
||||||
@@ -2217,7 +2217,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
/// imageBox双击事件处理方法
|
/// imageBox双击事件处理方法
|
||||||
/// 双击后弹出检测配置窗口
|
/// 双击后弹出检测配置窗口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void imageBox_DoubleClick(object sender, EventArgs e)
|
private void ImageBox_DoubleClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ namespace JoyD.Windows.CS
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
// 初始化定时器
|
// 初始化定时器
|
||||||
_timer = new Timer();
|
_timer = new Timer { Interval = 1000 };
|
||||||
_timer.Interval = 1000; // 1秒 = 1000毫秒
|
|
||||||
_timer.Tick += Timer_Tick;
|
_timer.Tick += Timer_Tick;
|
||||||
|
|
||||||
// 注册窗口事件
|
// 注册窗口事件
|
||||||
@@ -49,6 +48,7 @@ namespace JoyD.Windows.CS
|
|||||||
private void Setting_FormClosing(object sender, FormClosingEventArgs e)
|
private void Setting_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
_timer.Stop();
|
_timer.Stop();
|
||||||
|
mRealTimeImage?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -58,8 +58,48 @@ namespace JoyD.Windows.CS
|
|||||||
{
|
{
|
||||||
// 这里可以添加每秒需要执行的代码
|
// 这里可以添加每秒需要执行的代码
|
||||||
// 例如:更新界面数据、检查状态等
|
// 例如:更新界面数据、检查状态等
|
||||||
|
if (DesignMode || this.IsDisposed || this.Disposing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 线程安全检查 - 确保在UI线程上执行
|
||||||
|
if (this.InvokeRequired)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.BeginInvoke(new Action(UpdatePictureBoxImage));
|
||||||
|
}
|
||||||
|
catch (ObjectDisposedException)
|
||||||
|
{
|
||||||
|
// 控件已释放,忽略
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdatePictureBoxImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新PictureBox图像的辅助方法
|
||||||
|
/// </summary>
|
||||||
|
private void UpdatePictureBoxImage()
|
||||||
|
{
|
||||||
|
// 安全更新图像
|
||||||
|
if (pictureBoxTemperatureDisplay != null && !pictureBoxTemperatureDisplay.IsDisposed)
|
||||||
|
{
|
||||||
|
// 保存旧图像引用,以便设置新图像后释放
|
||||||
|
Image oldImage = pictureBoxTemperatureDisplay.Image;
|
||||||
|
|
||||||
|
// 设置新图像
|
||||||
|
pictureBoxTemperatureDisplay.Image = mRealTimeImage;
|
||||||
|
|
||||||
|
// 释放旧图像(如果不是当前设置的图像)
|
||||||
|
if (oldImage != null && oldImage != mRealTimeImage)
|
||||||
|
{
|
||||||
|
try { oldImage.Dispose(); } catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Image mRealTimeImage = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实时图像属性
|
/// 实时图像属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -69,51 +109,12 @@ namespace JoyD.Windows.CS
|
|||||||
{
|
{
|
||||||
if (DesignMode || this.IsDisposed || this.Disposing || pictureBoxTemperatureDisplay == null || pictureBoxTemperatureDisplay.IsDisposed)
|
if (DesignMode || this.IsDisposed || this.Disposing || pictureBoxTemperatureDisplay == null || pictureBoxTemperatureDisplay.IsDisposed)
|
||||||
return null;
|
return null;
|
||||||
return pictureBoxTemperatureDisplay.Image;
|
return mRealTimeImage;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
UpdateRealTimeTemperatureImage(value);
|
mRealTimeImage?.Dispose();
|
||||||
}
|
mRealTimeImage = value;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 同步更新实时温度图像
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="image">要显示的图像</param>
|
|
||||||
public void UpdateRealTimeTemperatureImage(Image image)
|
|
||||||
{
|
|
||||||
if (DesignMode || this.IsDisposed || this.Disposing)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 线程安全检查 - 确保在UI线程上执行
|
|
||||||
if (this.InvokeRequired)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.BeginInvoke(new Action<Image>(UpdateRealTimeTemperatureImage), image);
|
|
||||||
}
|
|
||||||
catch (ObjectDisposedException)
|
|
||||||
{
|
|
||||||
// 控件已释放,忽略
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 安全更新图像
|
|
||||||
if (pictureBoxTemperatureDisplay != null && !pictureBoxTemperatureDisplay.IsDisposed)
|
|
||||||
{
|
|
||||||
// 保存旧图像引用,以便设置新图像后释放
|
|
||||||
Image oldImage = pictureBoxTemperatureDisplay.Image;
|
|
||||||
|
|
||||||
// 设置新图像
|
|
||||||
pictureBoxTemperatureDisplay.Image = image;
|
|
||||||
|
|
||||||
// 释放旧图像
|
|
||||||
if (oldImage != null && oldImage != image)
|
|
||||||
{
|
|
||||||
try { oldImage.Dispose(); } catch { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user