From 9c3f95ce73d9568df7703d2099f097c0742c6dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sun, 26 Dec 2021 19:26:04 +0100 Subject: [PATCH 1/2] Flowed cancellation token to TcpClient.ConnectAsync in .NET 5.0 target --- S7.Net/PlcAsynchronous.cs | 9 +++++++-- S7.Net/S7.Net.csproj | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/S7.Net/PlcAsynchronous.cs b/S7.Net/PlcAsynchronous.cs index a58f6293..f75cf233 100644 --- a/S7.Net/PlcAsynchronous.cs +++ b/S7.Net/PlcAsynchronous.cs @@ -25,7 +25,7 @@ public partial class Plc /// A task that represents the asynchronous open operation. 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 @@ await queue.Enqueue(async () => } } - private async Task ConnectAsync() + private async Task 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(); } diff --git a/S7.Net/S7.Net.csproj b/S7.Net/S7.Net.csproj index 85ef368c..fa85b08c 100644 --- a/S7.Net/S7.Net.csproj +++ b/S7.Net/S7.Net.csproj @@ -1,7 +1,7 @@  - net452;netstandard2.0;netstandard1.3 + net452;netstandard2.0;netstandard1.3;net5.0 true Properties\S7.Net.snk S7.Net.UnitTest From 5d3f01e59e61720b3dedd3342b433824b6287214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Sun, 26 Dec 2021 19:26:44 +0100 Subject: [PATCH 2/2] Updated AppVeyor image to VS 2022 to allow better conditional compilation --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 3e3100df..28da709e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -image: Visual Studio 2019 +image: Visual Studio 2022 configuration: Release install: - choco install gitversion.portable -y