diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs index 071edc9649eaa..89f6d1b0f1aa0 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs @@ -12,6 +12,7 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Microsoft.VisualStudio.Threading; using StreamJsonRpc; namespace Microsoft.CommonLanguageServerProtocol.Framework; @@ -326,18 +327,21 @@ private ValueTask ShutdownRequestExecutionQueueAsync() return queue.DisposeAsync(); } -#pragma warning disable VSTHRD100 /// /// Cleanup the server if we encounter a json rpc disconnect so that we can be restarted later. /// - private async void JsonRpc_Disconnected(object? sender, JsonRpcDisconnectedEventArgs e) + private void JsonRpc_Disconnected(object? sender, JsonRpcDisconnectedEventArgs e) { - // It is possible this gets called during normal shutdown and exit. - // ShutdownAsync and ExitAsync will no-op if shutdown was already triggered by something else. - await ShutdownAsync(message: "Shutdown triggered by JsonRpc disconnect").ConfigureAwait(false); - await ExitAsync().ConfigureAwait(false); + JsonRpc_DisconnectedAsync(sender, e).Forget(); + + async Task JsonRpc_DisconnectedAsync(object? sender, JsonRpcDisconnectedEventArgs e) + { + // It is possible this gets called during normal shutdown and exit. + // ShutdownAsync and ExitAsync will no-op if shutdown was already triggered by something else. + await ShutdownAsync(message: "Shutdown triggered by JsonRpc disconnect").ConfigureAwait(false); + await ExitAsync().ConfigureAwait(false); + } } -#pragma warning disable VSTHRD100 internal TestAccessor GetTestAccessor() {