Fixed issue where connecting could take very long and cancellation would not work (#78)

* Fixed issue where connecting could take very long and cancellation would not work

* Addressing feedback

* Remove warning suppression
This commit is contained in:
Mitchell Sternke
2016-10-06 10:15:59 -07:00
committed by GitHub
parent c6a2568075
commit 926cfbf3bc

View File

@@ -264,10 +264,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
}; };
// invoke callback notifications // invoke callback notifications
foreach (var activity in this.onConnectionActivities) invokeOnConnectionActivities(connectionInfo);
{
await activity(connectionInfo);
}
// try to get information about the connected SQL Server instance // try to get information about the connected SQL Server instance
try try
@@ -461,7 +458,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
try try
{ {
// create a task to connect asyncronously so that other requests are not blocked in the meantime RunConnectRequestHandlerTask(connectParams, requestContext);
await requestContext.SendResult(true);
}
catch
{
await requestContext.SendResult(false);
}
}
private void RunConnectRequestHandlerTask(ConnectParams connectParams, RequestContext<bool> requestContext)
{
// create a task to connect asynchronously so that other requests are not blocked in the meantime
Task.Run(async () => Task.Run(async () =>
{ {
try try
@@ -479,12 +487,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
await ServiceHost.SendEvent(ConnectionCompleteNotification.Type, result); await ServiceHost.SendEvent(ConnectionCompleteNotification.Type, result);
} }
}); });
await requestContext.SendResult(true);
}
catch
{
await requestContext.SendResult(false);
}
} }
/// <summary> /// <summary>
@@ -723,5 +725,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
} }
} }
} }
private void invokeOnConnectionActivities(ConnectionInfo connectionInfo)
{
foreach (var activity in this.onConnectionActivities)
{
// not awaiting here to allow handlers to run in the background
activity(connectionInfo);
}
}
} }
} }