Update KcpNetClient.cs

This commit is contained in:
CortexCore 2024-06-16 09:34:17 +08:00
parent b368e8258b
commit 22f318c8f6
1 changed files with 10 additions and 4 deletions

View File

@ -67,9 +67,16 @@ namespace BITKit.Net
private async void ConnectionCallback(bool x)
{
if (x is false) return;
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
OnConnected?.Invoke();
if (x)
{
OnConnected?.Invoke();
}
else
{
OnDisconnected?.Invoke();
}
}
private void Tick(object sender, ElapsedEventArgs e)
@ -290,7 +297,7 @@ namespace BITKit.Net
private async void OnDisconnectInternal()
{
BIT4Log.Log<KcpNetClient>("断开连接");
//BIT4Log.Log<KcpNetClient>("断开连接");
_timer.Stop();
try
{
@ -298,7 +305,6 @@ namespace BITKit.Net
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext,
BITApp.CancellationToken);
_isConnected.RemoveElement(this);
OnDisconnected?.Invoke();
}
catch (OperationCanceledException)
{