修改InfoImage资源处理逻辑,从释放资源改为简单清理
This commit is contained in:
@@ -81,9 +81,10 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新InfoImage显示
|
/// 更新InfoImage显示
|
||||||
/// 1. 如果断开,显示重连信息
|
/// 1. 如果暂停,显示暂停信息
|
||||||
/// 2. 否则如果暂停,显示暂停信息
|
/// 2. 否则如果Ping不通或断开,显示重连信息
|
||||||
/// 3. 最后调用更新UI
|
/// 3. 否则清空InfoImage
|
||||||
|
/// 4. 最后调用更新UI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateInfo()
|
private void UpdateInfo()
|
||||||
{
|
{
|
||||||
@@ -95,17 +96,9 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
{
|
{
|
||||||
lock (_infoImageLock)
|
lock (_infoImageLock)
|
||||||
{
|
{
|
||||||
// 释放之前的InfoImage资源
|
// 清理InfoImage
|
||||||
if (_infoImage != null)
|
if (_infoImage != null)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
_infoImage.Dispose();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"释放InfoImage资源异常: {ex.Message}");
|
|
||||||
}
|
|
||||||
_infoImage = null;
|
_infoImage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,9 +108,39 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
bool isPaused = _isPaused; // 使用_isPaused标志判断暂停状态
|
bool isPaused = _isPaused; // 使用_isPaused标志判断暂停状态
|
||||||
bool isPingFailed = !IsDevicePingable;
|
bool isPingFailed = !IsDevicePingable;
|
||||||
|
|
||||||
// 如果需要显示信息,创建InfoImage
|
// 根据用户要求的优先级显示信息:先检查暂停状态,然后再检查Ping状态和连接状态
|
||||||
if (isDisconnected || isReconnecting || isPaused || isPingFailed)
|
if (isPaused)
|
||||||
{
|
{
|
||||||
|
// 暂停状态 - 最高优先级
|
||||||
|
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||||
|
using (Graphics g = Graphics.FromImage(_infoImage))
|
||||||
|
{
|
||||||
|
// 设置半透明背景
|
||||||
|
using (SolidBrush brush = new SolidBrush(Color.FromArgb(128, Color.Black)))
|
||||||
|
{
|
||||||
|
g.FillRectangle(brush, 0, 0, BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绘制暂停文本
|
||||||
|
string text = "暂停";
|
||||||
|
Color textColor = Color.Red;
|
||||||
|
|
||||||
|
using (Font font = new Font("Arial", 48, FontStyle.Bold))
|
||||||
|
using (SolidBrush textBrush = new SolidBrush(textColor))
|
||||||
|
{
|
||||||
|
StringFormat format = new StringFormat();
|
||||||
|
format.Alignment = StringAlignment.Center;
|
||||||
|
|
||||||
|
// 将主文本居中显示
|
||||||
|
g.DrawString(text, font, textBrush,
|
||||||
|
new RectangleF(0, BUFFER_HEIGHT / 3, BUFFER_WIDTH, BUFFER_HEIGHT / 3),
|
||||||
|
format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isPingFailed || isDisconnected || isReconnecting)
|
||||||
|
{
|
||||||
|
// 非暂停状态下,检查Ping状态和连接状态
|
||||||
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||||
using (Graphics g = Graphics.FromImage(_infoImage))
|
using (Graphics g = Graphics.FromImage(_infoImage))
|
||||||
{
|
{
|
||||||
@@ -131,30 +154,19 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
string text = "";
|
string text = "";
|
||||||
Color textColor = Color.White;
|
Color textColor = Color.White;
|
||||||
|
|
||||||
// 根据要求的优先级显示信息:先检查Ping状态和连接状态,最后检查暂停状态
|
if (isReconnecting)
|
||||||
if (isPingFailed || isDisconnected || isReconnecting)
|
{
|
||||||
{
|
text = "正在重连...";
|
||||||
// Ping不通或断开连接状态
|
textColor = Color.Yellow;
|
||||||
if (isReconnecting)
|
|
||||||
{
|
|
||||||
text = "正在重连...";
|
|
||||||
textColor = Color.Yellow;
|
|
||||||
}
|
|
||||||
else if (isDisconnected)
|
|
||||||
{
|
|
||||||
text = "连接断开";
|
|
||||||
textColor = Color.Red;
|
|
||||||
}
|
|
||||||
else if (isPingFailed)
|
|
||||||
{
|
|
||||||
text = "连接断开";
|
|
||||||
textColor = Color.Red;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (isPaused)
|
else if (isDisconnected)
|
||||||
{
|
{
|
||||||
// 暂停状态
|
text = "连接断开";
|
||||||
text = "暂停";
|
textColor = Color.Red;
|
||||||
|
}
|
||||||
|
else if (isPingFailed)
|
||||||
|
{
|
||||||
|
text = "连接断开";
|
||||||
textColor = Color.Red;
|
textColor = Color.Red;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,9 +184,10 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 否则清空InfoImage(已在开头处理)
|
||||||
|
|
||||||
// 设置显示标志
|
// 设置显示标志
|
||||||
_isDisplayingInfo = (isDisconnected || isReconnecting || isPaused);
|
_isDisplayingInfo = (isPaused || isDisconnected || isReconnecting);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用更新UI
|
// 调用更新UI
|
||||||
|
|||||||
Reference in New Issue
Block a user