mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 14:28:25 +08:00
Flowed cancellation token to TcpClient.ConnectAsync in .NET 5.0 target
This commit is contained in:
@@ -25,7 +25,7 @@ namespace S7.Net
|
||||
/// <returns>A task that represents the asynchronous open operation.</returns>
|
||||
public async Task OpenAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var stream = await ConnectAsync().ConfigureAwait(false);
|
||||
var stream = await ConnectAsync(cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await queue.Enqueue(async () =>
|
||||
@@ -44,11 +44,16 @@ namespace S7.Net
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<NetworkStream> ConnectAsync()
|
||||
private async Task<NetworkStream> ConnectAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
tcpClient = new TcpClient();
|
||||
ConfigureConnection();
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
await tcpClient.ConnectAsync(IP, Port, cancellationToken).ConfigureAwait(false);
|
||||
#else
|
||||
await tcpClient.ConnectAsync(IP, Port).ConfigureAwait(false);
|
||||
#endif
|
||||
return tcpClient.GetStream();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net452;netstandard2.0;netstandard1.3</TargetFrameworks>
|
||||
<TargetFrameworks>net452;netstandard2.0;netstandard1.3;net5.0</TargetFrameworks>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>Properties\S7.Net.snk</AssemblyOriginatorKeyFile>
|
||||
<InternalsVisibleTo>S7.Net.UnitTest</InternalsVisibleTo>
|
||||
|
||||
Reference in New Issue
Block a user