优化InfoImage使用方式,避免频繁Dispose,改为直接清除并重绘
This commit is contained in:
@@ -811,18 +811,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
// 清除InfoImage和显示标志
|
||||
lock (_infoImageLock)
|
||||
{
|
||||
if (_infoImage != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_infoImage.Dispose();
|
||||
_infoImage = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"释放InfoImage资源异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
_infoImage = null; // 直接设为null,不需要Dispose
|
||||
}
|
||||
_isDisplayingInfo = false;
|
||||
|
||||
@@ -877,21 +866,13 @@ namespace JoyD.Windows.CS.Toprie
|
||||
// 在InfoImage中显示连接断开信息
|
||||
lock (_infoImageLock)
|
||||
{
|
||||
// 释放之前的InfoImage资源
|
||||
if (_infoImage != null)
|
||||
// 如果_infoImage为null,则创建新对象
|
||||
if (_infoImage == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_infoImage.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"释放InfoImage资源异常: {ex.Message}");
|
||||
}
|
||||
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
}
|
||||
|
||||
// 创建新的InfoImage并绘制断开连接字样
|
||||
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
// 直接在现有InfoImage上重绘,不需要Dispose
|
||||
using (Graphics g = Graphics.FromImage(_infoImage))
|
||||
{
|
||||
// 设置半透明背景
|
||||
@@ -936,21 +917,13 @@ namespace JoyD.Windows.CS.Toprie
|
||||
// 在InfoImage中显示正在重连信息
|
||||
lock (_infoImageLock)
|
||||
{
|
||||
// 释放之前的InfoImage资源
|
||||
if (_infoImage != null)
|
||||
// 如果_infoImage为null,则创建新对象
|
||||
if (_infoImage == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_infoImage.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"释放InfoImage资源异常: {ex.Message}");
|
||||
}
|
||||
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
}
|
||||
|
||||
// 创建新的InfoImage并绘制正在重连字样
|
||||
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
// 直接在现有InfoImage上重绘,不需要Dispose
|
||||
using (Graphics g = Graphics.FromImage(_infoImage))
|
||||
{
|
||||
// 设置半透明背景
|
||||
|
||||
Reference in New Issue
Block a user