解决xml告警问题,解决多发重连问题
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<DocumentationFile>bin\Release\JoyD.Windows.CS.CubeLib.xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>
|
<ApplicationIcon>
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||||
//通过使用 "*",如下所示:
|
//通过使用 "*",如下所示:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.1.3")]
|
[assembly: AssemblyVersion("1.0.2.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.1.7")]
|
[assembly: AssemblyFileVersion("1.0.2.0")]
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace JoyD.Windows.CS.WebSocket
|
|||||||
private string _status = "disconnected";
|
private string _status = "disconnected";
|
||||||
private int _reconnectAttempts = 0;
|
private int _reconnectAttempts = 0;
|
||||||
private int _reconnectDelay = 1000;
|
private int _reconnectDelay = 1000;
|
||||||
|
private volatile bool _isReconnectScheduled = false;
|
||||||
|
|
||||||
// 事件
|
// 事件
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -374,7 +375,12 @@ namespace JoyD.Windows.CS.WebSocket
|
|||||||
{
|
{
|
||||||
ChangeStatus("reconnecting");
|
ChangeStatus("reconnecting");
|
||||||
Reconnecting?.Invoke(this, EventArgs.Empty);
|
Reconnecting?.Invoke(this, EventArgs.Empty);
|
||||||
ScheduleReconnect();
|
// 使用Try模式避免重复调度
|
||||||
|
try {
|
||||||
|
ScheduleReconnect();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogError("调度重连失败: " + ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -436,7 +442,15 @@ namespace JoyD.Windows.CS.WebSocket
|
|||||||
|
|
||||||
private void ScheduleReconnect()
|
private void ScheduleReconnect()
|
||||||
{
|
{
|
||||||
|
// 防止重复调度重连
|
||||||
|
if (_isReconnectScheduled)
|
||||||
|
{
|
||||||
|
Log("重连已计划,跳过本次调度");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CancelReconnect();
|
CancelReconnect();
|
||||||
|
_isReconnectScheduled = true;
|
||||||
|
|
||||||
var delay = Math.Min(_reconnectDelay, _config.MaxReconnectDelay);
|
var delay = Math.Min(_reconnectDelay, _config.MaxReconnectDelay);
|
||||||
Log("准备重连,延迟: " + delay + "ms");
|
Log("准备重连,延迟: " + delay + "ms");
|
||||||
@@ -444,6 +458,7 @@ namespace JoyD.Windows.CS.WebSocket
|
|||||||
_reconnectTimer = new System.Timers.Timer(delay);
|
_reconnectTimer = new System.Timers.Timer(delay);
|
||||||
_reconnectTimer.Elapsed += (sender, e) =>
|
_reconnectTimer.Elapsed += (sender, e) =>
|
||||||
{
|
{
|
||||||
|
_isReconnectScheduled = false;
|
||||||
_reconnectAttempts++;
|
_reconnectAttempts++;
|
||||||
Log("开始重连,尝试次数: " + _reconnectAttempts);
|
Log("开始重连,尝试次数: " + _reconnectAttempts);
|
||||||
Connect();
|
Connect();
|
||||||
@@ -465,6 +480,7 @@ namespace JoyD.Windows.CS.WebSocket
|
|||||||
_reconnectTimer = null;
|
_reconnectTimer = null;
|
||||||
Log("已取消重连计划");
|
Log("已取消重连计划");
|
||||||
}
|
}
|
||||||
|
_isReconnectScheduled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FlushQueue()
|
private void FlushQueue()
|
||||||
|
|||||||
Reference in New Issue
Block a user