If an invalid value for a connection string is passed to SDEWorkspaceFactory.OpenFromString(), the call hangs:
If I break execution, I can see from the call stack that control is still with the unmanaged code. Unfortunately, this OpenFromString doesn't offer a timeout. What I need to do is, within my .NET managed code, cancel the call to OpenFromString after a certain timeout period. I've tried a couple of approaches, including the following:
In this case, task.Wait() always returns false, and task.Result() is always null, even if a valid value for the connection string is passed.
I've also tried the following approach:
In this case, if a valid value for the connection string is passed, execution works as expected, but if an invalid value is passed, the execution still hangs in the unmanaged code, and thread.Join() never returns.
Any suggestions on how to do this?
Code:
IWorkspaceFactory workspaceFactory = _workspaceFactory.OpenFromString("InvalidConnectionString", 0);Code:
Task<IWorkspace> task = new Task<IWorkspace>(() =>
{
return _workspaceFactory.OpenFromString("InvalidConnectionString", 0);
});
if (!task.Wait(10000))
{
throw new TimeoutException();
}
IWorkspace workspace = task.Result;I've also tried the following approach:
Code:
IWorkspace workspace = null;
Thread thread = new Thread(() =>
{
workspace = _workspaceFactory.OpenFromString("InvalidConnectionString", 0);
});
thread.Start();
if (!thread.Join(10000))
{
throw new TimeoutException();
}Any suggestions on how to do this?