I created a feature layer in my ArcGIS Online organization. The URL looks like: https://services7.arcgis.com/<unique string>/arcgis/rest/services/Test_Feature_Layer/FeatureServer
If I sign out of the licensing portal in ArcGIS Pro and then run the code shown below with my URL, it will freeze at the constructor on line 9.
How can I avoid this frozen state?
public bool TestConnection(string url)
{
return RunMCTOnNonGUIThread(() =>
{
Geodatabase gdb = null;
try
{
var service = new ServiceConnectionProperties(new Uri(url));
gdb = new Geodatabase(service);
return true;
}
catch
{
return false;
}
finally
{
gdb?.Dispose();
}
});
}
private T RunMCTOnNonGUIThread<T>(Func<T> function)
=> Task.Run(() => QueuedTask.Run(function)).Result;
Solved! Go to Solution.
try this: - Your utility method is likely causing a deadlock. u dont need the extra Task wrapper around the QueuedTask. Also, using Task.Result should be avoided (as it can cause deadlocks).
public Task<bool> TestConnectionAsync(string url)
{
return QueuedTask.Run(() =>
{
try
{
var service = new ServiceConnectionProperties(new Uri(url));
using (var gdb = new Geodatabase(service))
return true;
}
catch
{
return false;
}
});
}
//usage
var connect_ok = await TestConnectionAsync("connection_string");
not from the UI. At some point u have to go onto the QueuedTask.
Once on the QueuedTask u can call ArcGISPortal IsSignedOn()
try this: - Your utility method is likely causing a deadlock. u dont need the extra Task wrapper around the QueuedTask. Also, using Task.Result should be avoided (as it can cause deadlocks).
public Task<bool> TestConnectionAsync(string url)
{
return QueuedTask.Run(() =>
{
try
{
var service = new ServiceConnectionProperties(new Uri(url));
using (var gdb = new Geodatabase(service))
return true;
}
catch
{
return false;
}
});
}
//usage
var connect_ok = await TestConnectionAsync("connection_string");
Thanks for the info. I am not going to be able to verify if this is the solution for a while.
Properly adding an async from our UI to this method would be a very difficult task.
Is there a way to check if I am currently signed into ArcGIS portal before attempting to call the Geodatabase constructor?
not from the UI. At some point u have to go onto the QueuedTask.
Once on the QueuedTask u can call ArcGISPortal IsSignedOn()