初始化后延迟100ms再连接

This commit is contained in:
zqm
2026-02-05 17:23:14 +08:00
parent 2eb1aa6722
commit 2af36569fa

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Timers; using System.Timers;
using System.Threading; using System.Threading;
using WebSocketSharp; using WebSocketSharp;
using System.Threading.Tasks;
namespace JoyD.Windows.CS.WebSocket namespace JoyD.Windows.CS.WebSocket
{ {
@@ -84,7 +85,12 @@ namespace JoyD.Windows.CS.WebSocket
// 如果AutoConnect设置为true则自动连接 // 如果AutoConnect设置为true则自动连接
if (_config.AutoConnect) if (_config.AutoConnect)
{ {
// 使用异步延迟连接,给调用方足够的时间挂接事件处理程序
Task.Factory.StartNew(() =>
{
Thread.Sleep(100); // 延迟100毫秒
Connect(); Connect();
}, TaskCreationOptions.LongRunning);
} }
} }