diff --git a/csharp/src/Ice/ConnectionI.cs b/csharp/src/Ice/ConnectionI.cs index 13c0172bdcf..bdb68e101da 100644 --- a/csharp/src/Ice/ConnectionI.cs +++ b/csharp/src/Ice/ConnectionI.cs @@ -607,15 +607,23 @@ public override bool startAsync(int operation, Ice.Internal.AsyncCallback comple observerStartWrite(_writeStream.getBuffer()); } - bool completed; - if (_transceiver.startWrite(_writeStream.getBuffer(), completedCallback, this, out completed)) + bool messageWritten = false; + bool completedSynchronously = + _transceiver.startWrite( + _writeStream.getBuffer(), + completedCallback, + this, + out messageWritten); + // If the startWrite call consumed the complete buffer, we assume the message is sent now for + // at-most-once semantics. + if (messageWritten && _sendStreams.Count > 0) { - // If the write completed immediately and the buffer - if (completed && _sendStreams.Count > 0) - { - // The whole message is written, assume it's sent now for at-most-once semantics. - _sendStreams.First.Value.isSent = true; - } + _sendStreams.First.Value.isSent = true; + } + + if (completedSynchronously) + { + // If the write completed synchronously, we need to call the completedCallback. completedCallback(this); } }