The system wouldn't let me post my whole code block, so this will be the main code that had the issues. My next post will be the beginning of the code.
Try
' Using comReleaser As ESRI.ArcGIS.ADF.ComReleaser = New ESRI.ArcGIS.ADF.ComReleaser()
Dim pFeat As IFeature = Nothing
Dim pEnumFeat As IEnumFeature = CType(pMap.FeatureSelection, IEnumFeature)
'Dim pEnumFeat As IEnumFeature = CType(pFLayer.SelectionSet, IEnumFeature)
pEnumFeat.Reset()
'Dim pFCur As IFeatureCursor = Nothing
Dim pSF As ISpatialFilter
pSF = New SpatialFilter
Dim pTopoOp As ITopologicalOperator
Dim pLargestAdj As IFeature = Nothing
Dim sliverFeat As IFeature = Nothing
sliverFeat = pEnumFeat.Next
Do Until sliverFeat Is Nothing
'this is really the smallest
'---------------------------------------------------------------------
pLargestAdj = GetLargestAdjacent(sliverFeat, True, pSF, pFClass)
'---------------------------------------------------------------------
If Not pLargestAdj Is Nothing Then
pTopoOp = CType(pLargestAdj.ShapeCopy, ITopologicalOperator)
pLargestAdj.Shape = pTopoOp.Union(sliverFeat.ShapeCopy)
updateFeature(m_pFLayer.FeatureClass, pLargestAdj.OID, pLargestAdj.Shape)
Marshal.FinalReleaseComObject(pLargestAdj)
sliverFeat.Delete()
Marshal.FinalReleaseComObject(sliverFeat)
GC.Collect()
GC.WaitForPendingFinalizers()
Else
Debug.Print("nothing adjacent to: " & sliverFeat.OID)
End If
nCurRecNo = nCurRecNo + 1
My.ArcMap.Application.StatusBar.Message(0) = nCurRecNo.ToString & "/" & n.ToString & " records complete."
Application.DoEvents()
sliverFeat = pEnumFeat.Next
Loop
'Stop editing and save the edits
pEditor.StopEditing(True)
Runtime.InteropServices.Marshal.FinalReleaseComObject(pLargestAdj)
'End Using
Catch ex As Exception
MsgBox("Error: " & ex.StackTrace, , "RElimAddinPB_onClick")
End Try
m_gdbPath = ""
'refresh the selectionset on screen
Dim pActiveView As IActiveView
pActiveView = CType(pMap, IActiveView)
pMxDoc.CurrentContentsView.Refresh(Nothing)
pActiveView.Refresh()
'Let the user know it completed successfully
MsgBox("Complete")
'Show the user how long it took to process
Dim tElapsed As TimeSpan = DateTime.Now.Subtract(tStartTime)
MsgBox(nCurRecNo.ToString + " records in: " + tElapsed.Hours.ToString + " hours " + tElapsed.Minutes.ToString + " minutes " + tElapsed.Seconds.ToString + " seconds.")
m_pFLayer = Nothing
Catch ex As Exception
MsgBox(ex.StackTrace)
MsgBox(ex.Message)
End Try
End Sub
Function GetLargestAdjacent(ByVal pFeat As IFeature, ByVal getSecondLargest As Boolean, ByVal pSF As ISpatialFilter, ByVal pFC As IFeatureClass) As IFeature
'MsgBox("in get largest adjacent")
Try
Dim pFCur As IFeatureCursor
pSF.Geometry = pFeat.Shape
pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
'pFcur = pFC.Search(pSF, False)
pFcur = pFC.Update(pSF, False)
If pFC.FeatureCount(pSF) < 3 Then
getSecondLargest = False
End If
Using comReleaser As ESRI.ArcGIS.ADF.ComReleaser = New ESRI.ArcGIS.ADF.ComReleaser()
Dim pFeat2 As IFeature = Nothing, pLargestFeat As IFeature = Nothing
comReleaser.ManageLifetime(pFeat2)
comReleaser.ManageLifetime(pFcur)
Dim dMaxArea As Double = 0
pFeat2 = pFcur.NextFeature
Do Until pFeat2 Is Nothing
If Not pFeat2 Is pFeat Then
If pLargestFeat Is Nothing Then
pLargestFeat = pFeat2
dMaxArea = GetArea(CType(pFeat2.Shape, IArea))
pFcur.Flush()
'Runtime.InteropServices.Marshal.FinalReleaseComObject(pLargestFeat)
Else
If GetArea(CType(pFeat2.Shape, IArea)) > dMaxArea Then
pLargestFeat = pFeat2
dMaxArea = GetArea(CType(pFeat2.Shape, IArea))
End If
End If
End If
pFeat2 = Nothing
pFCur.Flush()
pFeat2 = pFCur.NextFeature
Loop
Marshal.ReleaseComObject(pFcur)
'comReleaser.Dispose()
If getSecondLargest Then
'pFCur = pFC.Search(pSF, False)
'pFcur = m_pFLayer.FeatureClass.Search(pSF, False)
pFcur = m_pFLayer.FeatureClass.Update(pSF, False)
Dim pSecondLargestFeat As IFeature = Nothing
Dim dSecondMaxArea As Double = 0
pFeat2 = pFcur.NextFeature
Do Until pFeat2 Is Nothing
comReleaser.ManageLifetime(pFcur)
If Not pFeat2 Is pLargestFeat Then
If Not pFeat2 Is pFeat Then
If pSecondLargestFeat Is Nothing Then
pSecondLargestFeat = pFeat2
dSecondMaxArea = GetArea(CType(pFeat2.Shape, IArea))
Else
If GetArea(CType(pFeat2.Shape, IArea)) > dSecondMaxArea Then
pSecondLargestFeat = pFeat2
dSecondMaxArea = GetArea(CType(pFeat2.Shape, IArea))
End If
End If
End If
End If
pFeat2 = pFcur.NextFeature
pFcur.Flush()
Loop
pLargestFeat = pSecondLargestFeat
End If
Marshal.ReleaseComObject(pFcur)
GetLargestAdjacent = pLargestFeat
'comReleaser.Dispose()
End Using
Catch ex As Exception
MsgBox(ex.Message, , "Ex routine")
MsgBox(ex.StackTrace, , "Ex routine")
GetLargestAdjacent = Nothing
End Try
End Function
Private Sub updateFeature(ByVal fc As IFeatureClass, ByVal oid As Integer, ByVal newGeom As IGeometry)
Dim queryFilter As IQueryFilter = New QueryFilter() With { _
.WhereClause = Convert.ToString(fc.OIDFieldName) & " = " & oid.ToString() _
}
Dim featureCursor As IFeatureCursor = fc.Update(queryFilter, False)
Dim featureToUpdate As IFeature = featureCursor.NextFeature()
featureToUpdate.Shape = newGeom
featureCursor.UpdateFeature(featureToUpdate)
featureCursor.Flush()
Marshal.FinalReleaseComObject(featureCursor)
Marshal.FinalReleaseComObject(featureToUpdate)
'Marshal.FinalReleaseComObject(fc)
End Sub
Function GetArea(ByVal pArea As IArea) As Double
GetArea = pArea.Area
End Function
Protected Overrides Sub OnUpdate()
Enabled = My.ArcMap.Application IsNot Nothing
End Sub
End Class