Select to view content in your preferred language

Geodatabase constructor hangs with organziation URL

472
4
Jump to solution
08-01-2023 08:57 AM
KarlBeal
New Contributor II

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;

 

2 Solutions

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

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");

 

 

View solution in original post

CharlesMacleod
Esri Regular Contributor

not from the UI. At some point u have to go onto the QueuedTask.

Once on the QueuedTask u can call ArcGISPortal IsSignedOn() 

View solution in original post

0 Kudos
4 Replies
CharlesMacleod
Esri Regular Contributor

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");

 

 

KarlBeal
New Contributor II

Thanks for the info. I am not going to be able to verify if this is the solution for a while.

0 Kudos
KarlBeal
New Contributor II

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?

0 Kudos
CharlesMacleod
Esri Regular Contributor

not from the UI. At some point u have to go onto the QueuedTask.

Once on the QueuedTask u can call ArcGISPortal IsSignedOn() 

0 Kudos