Skip to content

Commit 336dd47

Browse files
committed
refactor: 更改关闭方法为同步方法
1 parent 0f328a3 commit 336dd47

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/BootstrapBlazor/Services/TcpSocket/DefaultTcpSocketClient.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public async ValueTask<bool> ConnectAsync(IPEndPoint endPoint, CancellationToken
5959
try
6060
{
6161
// 释放资源
62-
await CloseAsync("Already connected", token);
62+
Close();
6363

6464
// 创建新的 TcpClient 实例
6565
_client ??= new TcpClient(LocalEndPoint);
@@ -160,6 +160,11 @@ private async ValueTask ReceiveAsync()
160160
}
161161
}
162162

163+
public void Close()
164+
{
165+
Dispose(true);
166+
}
167+
163168
private void Dispose(bool disposing)
164169
{
165170
if (disposing)
@@ -191,10 +196,4 @@ public void Dispose()
191196
Dispose(true);
192197
GC.SuppressFinalize(this);
193198
}
194-
195-
public ValueTask<bool> CloseAsync(string msg, CancellationToken token = default)
196-
{
197-
Dispose(true);
198-
return new ValueTask<bool>(true);
199-
}
200199
}

src/BootstrapBlazor/Services/TcpSocket/ITcpSocketClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ public interface ITcpSocketClient : IDisposable
7474
/// <remarks>Once the connection or resource is closed, it cannot be reopened. Ensure that all necessary
7575
/// operations are completed before calling this method. This method is typically used to clean up resources when
7676
/// they are no longer needed.</remarks>
77-
ValueTask<bool> CloseAsync(string msg, CancellationToken token = default);
77+
void Close();
7878
}

0 commit comments

Comments
 (0)