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