tjfdownsouth

Cannot aquire lock

Discussion created by tjfdownsouth on Mar 3, 2012
Latest reply on Mar 14, 2012 by tjfdownsouth
I am getting a lock error when i try to access a layer in a filegeodatabase.  In the application i have a timer that checkes every 5 seconds if i am inside a polygon.  I have basically copied the code from 9.3 into 10 and now it will not work consistently because of this error.  I have tried firing the gargage collector and tried to manually release but it seems it is not closing even though i am telling it too.  If the timer is set to 15 seconds there is not a problem so i can only assume that 10 uses the garbage collector more and it is not releasing objects until it runs.

the code:
        private bool CheckPointInArea(string layerName, PointClass pt)
        {
            IFeatureClass featClass;
            IFeature feat;
            IFeatureCursor curs;
            bool bIsInCorr;

            bIsInCorr = false;

            // get the feature cursor
            IFeatureLayer flayer = null;
            for (int i = 0; i < axMapControl1.LayerCount; i++)
            {
                ILayer temp = axMapControl1.get_Layer(i);
                if (temp.Name == layerName)
                {
                    flayer = temp as IFeatureLayer;
                    temp = null;

                    break;
                }
            }

            if (flayer != null)
            {
                featClass = flayer.FeatureClass;
                curs = featClass.Search(null, false);
                feat = curs.NextFeature();

                while (feat != null)
                {
                    IPolygon poly;
                    poly = (IPolygon)feat.Shape;
                    if (TGGeoDb.CCorridor.IsPointIn(poly, pt) == true)
                    {
                        bIsInCorr = true;

                        Marshal.FinalReleaseComObject(feat);

                        break;
                    }
                    else
                    {
                        Marshal.FinalReleaseComObject(feat);
                        feat = curs.NextFeature();
                    }
                }

                Marshal.FinalReleaseComObject(flayer);
                Marshal.FinalReleaseComObject(featClass);
                Marshal.FinalReleaseComObject(curs);
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();

            return bIsInCorr;
        }

Outcomes