移除RealTimeImage属性的线程安全检查:作为后台变量,不直接操作UI,移除InvokeRequired相关代码以简化实现并提高性能,保留状态检查和资源管理逻辑
This commit is contained in:
@@ -102,46 +102,16 @@ namespace JoyD.Windows.CS
|
|||||||
private Image mRealTimeImage = null;
|
private Image mRealTimeImage = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实时图像属性
|
/// 实时图像属性
|
||||||
|
/// 作为后台变量,移除线程安全检查以提高性能
|
||||||
|
/// 注意:调用方需确保在合适的线程上下文中访问
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Image RealTimeImage
|
public Image RealTimeImage
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// 读取操作也需要线程安全检查
|
|
||||||
if (this.InvokeRequired)
|
|
||||||
{
|
|
||||||
return (Image)this.Invoke(new Func<Image>(() => mRealTimeImage));
|
|
||||||
}
|
|
||||||
return mRealTimeImage;
|
return mRealTimeImage;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
|
||||||
// 线程安全检查 - 确保在UI线程上执行
|
|
||||||
if (this.InvokeRequired)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// 使用Action委托设置值,避免闭包问题
|
|
||||||
this.BeginInvoke(new Action<Image>(SetRealTimeImageInternal), value);
|
|
||||||
}
|
|
||||||
catch (ObjectDisposedException)
|
|
||||||
{
|
|
||||||
// 控件已释放,释放传入的图像资源
|
|
||||||
value?.Dispose();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在UI线程上直接调用内部方法
|
|
||||||
SetRealTimeImageInternal(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 内部方法,在UI线程上安全地设置实时图像
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value">要设置的新图像</param>
|
|
||||||
private void SetRealTimeImageInternal(Image value)
|
|
||||||
{
|
{
|
||||||
// 防止重复设置相同的图像
|
// 防止重复设置相同的图像
|
||||||
if (mRealTimeImage == value)
|
if (mRealTimeImage == value)
|
||||||
@@ -174,4 +144,5 @@ namespace JoyD.Windows.CS
|
|||||||
mRealTimeImage = value;
|
mRealTimeImage = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user