cpicciri

Slow IGxlayer access/broken links

Discussion created by cpicciri on Jun 26, 2012
Latest reply on Jul 25, 2012 by jamesfreddyc
Hi everyone,

I am trying to write some code that will check a layer file for broken links when the layer gets loaded in code. The code below works fine but the very first line (red line of code below) where it checks to see if the layer file has a group layer is very slow. It's taking 25 to 30 seconds consistently and I don't know why. The code below is part of a much larger program and since this script will be used every time a layer is loaded, I cannot have it taking 30 seconds for every layer because in certain cituations, 30 to 40 layers can get loaded one after another.

Thanks for your time to read this.
Carlos

internal static bool IsLayerFileValid(IGxLayer pGxLayer)
{
    ICompositeLayer pCompositeLayer = null;
    IGroupLayer pGroupLayer = new GroupLayerClass();
    ILayer pLayer = null;
    IEnumLayer pEnumLayer = null;

    try
    {
if (!(pGxLayer.Layer is IGroupLayer))
        {
     if (pGxLayer.Layer.Valid == false)
     {
  return false;
     }
}
else
{
     //pGroupLayer = pGxLayer.Layer as IGroupLayer;
     pCompositeLayer = pGxLayer.Layer as ICompositeLayer;

     for (int counter = 0; counter < pCompositeLayer.Count; counter++)
     {
  pLayer = pCompositeLayer.get_Layer(counter);

  if (pLayer.Valid == false)
  {
      return false;
  }
     }
}

return true;
    }
    catch (Exception ex)
    {
MessageBox.Show(ex.Message);
return false;
//throw;
    }
}

Outcomes