mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
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:
@@ -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,24 +458,7 @@ 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);
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// open connection based on request details
|
|
||||||
ConnectionCompleteParams result = await ConnectionService.Instance.Connect(connectParams);
|
|
||||||
await ServiceHost.SendEvent(ConnectionCompleteNotification.Type, result);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
ConnectionCompleteParams result = new ConnectionCompleteParams()
|
|
||||||
{
|
|
||||||
Messages = ex.ToString()
|
|
||||||
};
|
|
||||||
await ServiceHost.SendEvent(ConnectionCompleteNotification.Type, result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
await requestContext.SendResult(true);
|
await requestContext.SendResult(true);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -487,6 +467,28 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// open connection based on request details
|
||||||
|
ConnectionCompleteParams result = await ConnectionService.Instance.Connect(connectParams);
|
||||||
|
await ServiceHost.SendEvent(ConnectionCompleteNotification.Type, result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ConnectionCompleteParams result = new ConnectionCompleteParams()
|
||||||
|
{
|
||||||
|
Messages = ex.ToString()
|
||||||
|
};
|
||||||
|
await ServiceHost.SendEvent(ConnectionCompleteNotification.Type, result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handle cancel connect requests
|
/// Handle cancel connect requests
|
||||||
/// </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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user