版本修改

This commit is contained in:
zqm
2026-05-07 09:17:23 +08:00
parent 0ee65e58fb
commit 4247b49791
9 changed files with 152 additions and 44 deletions

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyVersion("1.0.2.1")]
[assembly: AssemblyFileVersion("1.0.2.1")]

View File

@@ -22,6 +22,7 @@ namespace JoyD.Windows.CS.WebSocket
private int _reconnectAttempts = 0;
private int _reconnectDelay = 1000;
private volatile bool _isReconnectScheduled = false;
private volatile bool _isConnecting = false;
// 事件
/// <summary>
@@ -106,6 +107,16 @@ namespace JoyD.Windows.CS.WebSocket
return;
}
// 检查是否正在连接中
if (_isConnecting)
{
Log("WebSocket正在连接中跳过本次连接");
return;
}
// 设置正在连接标志
_isConnecting = true;
ChangeStatus("connecting");
Connecting?.Invoke(this, EventArgs.Empty);
@@ -157,6 +168,7 @@ namespace JoyD.Windows.CS.WebSocket
}
catch (Exception ex)
{
_isConnecting = false;
StopConnectTimeoutTimer();
LogError("WebSocket连接失败: " + ex.Message);
ChangeStatus("error");
@@ -174,6 +186,7 @@ namespace JoyD.Windows.CS.WebSocket
/// </summary>
public void Disconnect()
{
_isConnecting = false;
CancelReconnect();
StopHeartbeat();
StopConnectTimeoutTimer();
@@ -192,7 +205,7 @@ namespace JoyD.Windows.CS.WebSocket
/// </summary>
public void Reconnect()
{
if (_webSocket != null && _webSocket.ReadyState == WebSocketSharp.WebSocketState.Connecting)
if (_isConnecting || (_webSocket != null && _webSocket.ReadyState == WebSocketSharp.WebSocketState.Connecting))
{
Log("WebSocket正在连接中跳过本次重连");
return;
@@ -309,6 +322,7 @@ namespace JoyD.Windows.CS.WebSocket
// 私有方法
private void WebSocket_OnOpen(object sender, EventArgs e)
{
_isConnecting = false;
StopConnectTimeoutTimer();
ChangeStatus("connected");
_reconnectAttempts = 0;
@@ -347,6 +361,7 @@ namespace JoyD.Windows.CS.WebSocket
private void WebSocket_OnClose(object sender, CloseEventArgs e)
{
_isConnecting = false;
StopConnectTimeoutTimer();
StopHeartbeat();
Log("WebSocket连接关闭: " + e.Code + " " + e.Reason);
@@ -366,6 +381,7 @@ namespace JoyD.Windows.CS.WebSocket
private void WebSocket_OnError(object sender, ErrorEventArgs e)
{
_isConnecting = false;
StopConnectTimeoutTimer();
StopHeartbeat();
LogError("WebSocket错误: " + e.Message);