diff --git a/Emby.Dlna/PlayTo/DlnaHttpClient.cs b/Emby.Dlna/PlayTo/DlnaHttpClient.cs index 62156d1833..75ff542dd8 100644 --- a/Emby.Dlna/PlayTo/DlnaHttpClient.cs +++ b/Emby.Dlna/PlayTo/DlnaHttpClient.cs @@ -66,13 +66,15 @@ namespace Emby.Dlna.PlayTo } } - public Task GetDataAsync(string url, CancellationToken cancellationToken) + public async Task GetDataAsync(string url, CancellationToken cancellationToken) { using var request = new HttpRequestMessage(HttpMethod.Get, url); - return SendRequestAsync(request, cancellationToken); + + // Have to await here instead of returning the Task directly, otherwise request would be disposed too soon + return await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); } - public Task SendCommandAsync( + public async Task SendCommandAsync( string baseUrl, DeviceService service, string command, @@ -99,7 +101,8 @@ namespace Emby.Dlna.PlayTo request.Headers.TryAddWithoutValidation("contentFeatures.dlna.org", header); } - return SendRequestAsync(request, cancellationToken); + // Have to await here instead of returning the Task directly, otherwise request would be disposed too soon + return await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); } } }