From 328fb30db2778b5e53c979147efb895b541f6697 Mon Sep 17 00:00:00 2001 From: Karl Burtram Date: Thu, 19 Oct 2017 16:05:24 -0700 Subject: [PATCH] Switch back to Tasks in binding queue (#510) --- .../LanguageServices/BindingQueue.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs index b57f960f..feb0b302 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs @@ -288,7 +288,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices CancellationTokenSource cancelToken = new CancellationTokenSource(); // run the operation in a separate thread - var bindThread = new Thread(() => + var bindTask = Task.Run(() => { try { @@ -304,11 +304,10 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices result = queueItem.ErrorHandler(ex); } } - }, BindingQueue.QueueThreadStackSize); - bindThread.Start(); - + }); + // check if the binding tasks completed within the binding timeout - if (bindThread.Join(bindTimeout)) + if (bindTask.Wait(bindTimeout)) { queueItem.Result = result; } @@ -324,12 +323,9 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices lockTaken = false; - Task.Run(() => - { - // wait for the operation to complete before releasing the lock - bindThread.Join(); - bindingContext.BindingLock.Set(); - }).ContinueWithOnFaulted(t => Logger.Write(LogLevel.Error, "Binding queue threw exception " + t.Exception.ToString())); + bindTask + .ContinueWith((a) => bindingContext.BindingLock.Set()) + .ContinueWithOnFaulted(t => Logger.Write(LogLevel.Error, "Binding queue threw exception " + t.Exception.ToString())); } } catch (Exception ex)