From 9adbdcdefa042dbad7fea825ddb914cbcbae0346 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 20 Dec 2018 18:39:37 +0000 Subject: [PATCH] Feedback --- .../src/System/Data/SqlClient/SNI/SNIPacket.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs index 63420ce4cb63..60c361d2f103 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs @@ -23,7 +23,6 @@ internal class SNIPacket : IDisposable, IEquatable private ArrayPool _arrayPool = ArrayPool.Shared; private bool _isBufferFromArrayPool = false; - private ValueTask _asyncOperation; public SNIPacket() { } @@ -239,7 +238,6 @@ public void Reset() _offset = 0; _description = null; _completionCallback = null; - _asyncOperation = default; } /// @@ -250,7 +248,7 @@ public void Reset() public void ReadFromStreamAsync(Stream stream, SNIAsyncCallback callback) { // Treat local function as a static and pass all params otherwise as async will allocate - async ValueTask ReadFromStreamAsync(SNIPacket packet, SNIAsyncCallback cb, ValueTask valueTask) + async Task ReadFromStreamAsync(SNIPacket packet, SNIAsyncCallback cb, ValueTask valueTask) { bool error = false; try @@ -292,7 +290,7 @@ async ValueTask ReadFromStreamAsync(SNIPacket packet, SNIAsyncCallback cb, Value } // Not complete or error call the async local function to complete - _asyncOperation = ReadFromStreamAsync(this, callback, vt); + _ = ReadFromStreamAsync(this, callback, vt); } /// @@ -320,7 +318,7 @@ public void WriteToStream(Stream stream) public void WriteToStreamAsync(Stream stream, SNIAsyncCallback callback, SNIProviders provider, bool disposeAfterWriteAsync = false) { // Treat local function as a static and pass all params otherwise as async will allocate - async ValueTask WriteToStreamAsync(SNIPacket packet, SNIAsyncCallback cb, SNIProviders providers, bool disposeAfter, ValueTask valueTask) + async Task WriteToStreamAsync(SNIPacket packet, SNIAsyncCallback cb, SNIProviders providers, bool disposeAfter, ValueTask valueTask) { uint status = TdsEnums.SNI_SUCCESS; try @@ -345,6 +343,9 @@ async ValueTask WriteToStreamAsync(SNIPacket packet, SNIAsyncCallback cb, SNIPro if (vt.IsCompletedSuccessfully) { + // Read the result to register as complete for the ValueTask + vt.GetAwaiter().GetResult(); + callback(this, TdsEnums.SNI_SUCCESS); if (disposeAfterWriteAsync) @@ -357,7 +358,7 @@ async ValueTask WriteToStreamAsync(SNIPacket packet, SNIAsyncCallback cb, SNIPro } // Not complete or error call the async local function to complete - _asyncOperation = WriteToStreamAsync(this, callback, provider, disposeAfterWriteAsync, vt); + _ = WriteToStreamAsync(this, callback, provider, disposeAfterWriteAsync, vt); } ///