diff --git a/dotnet/src/Agents/Orchestration/OrchestrationResult.cs b/dotnet/src/Agents/Orchestration/OrchestrationResult.cs index 978e7bcca74b..755e164c963b 100644 --- a/dotnet/src/Agents/Orchestration/OrchestrationResult.cs +++ b/dotnet/src/Agents/Orchestration/OrchestrationResult.cs @@ -73,12 +73,24 @@ public async ValueTask GetValueAsync(TimeSpan? timeout = null, Cancellat if (timeout.HasValue) { - Task[] tasks = { this._completion.Task }; - if (!Task.WaitAll(tasks, timeout.Value)) +#if NET + try + { + await this._completion.Task.WaitAsync(timeout.Value, cancellationToken).ConfigureAwait(false); + } + catch (TimeoutException) + { + this._logger.LogOrchestrationResultTimeout(this.Orchestration, this.Topic); + throw; + } +#else + Task completedTask = await Task.WhenAny(this._completion.Task, Task.Delay(timeout.Value, cancellationToken)).ConfigureAwait(false); + if (completedTask != this._completion.Task) { this._logger.LogOrchestrationResultTimeout(this.Orchestration, this.Topic); throw new TimeoutException($"Orchestration did not complete within the allowed duration ({timeout})."); } +#endif } this._logger.LogOrchestrationResultComplete(this.Orchestration, this.Topic); diff --git a/dotnet/src/Agents/UnitTests/Orchestration/OrchestrationResultTests.cs b/dotnet/src/Agents/UnitTests/Orchestration/OrchestrationResultTests.cs index 69471949847c..d65a2c5e8b8c 100644 --- a/dotnet/src/Agents/UnitTests/Orchestration/OrchestrationResultTests.cs +++ b/dotnet/src/Agents/UnitTests/Orchestration/OrchestrationResultTests.cs @@ -77,7 +77,6 @@ public async Task GetValueAsync_WithTimeout_ThrowsTimeoutException_WhenTaskDoesN // Act & Assert TimeoutException exception = await Assert.ThrowsAsync(() => result.GetValueAsync(timeout).AsTask()); - Assert.Contains("Orchestration did not complete within the allowed duration", exception.Message); } [Fact]