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