ManageLifetime を使用する方法

投稿日:2016/9/1 (木) 更新日:

using ステートメントで dispose されるオブジェクトを管理

using ステートメント

public static void RecyclingInappropriateExample(IFeatureClass featureClass, Boolean
    using(ComReleaser comReleaser = new ComReleaser())
        // Create a search cursor.
        IFeatureCursor featureCursor = featureClass.Search(null, enableRecycling);
        // Get the first two geometries and see if they intersect.
        IFeature feature1 = featureCursor.NextFeature();
        IFeature feature2 = featureCursor.NextFeature();
        IRelationalOperator relationalOperator = (IRelationalOperator)feature1.Shape;
        Boolean geometriesEqual = relationalOperator.Equals(feature2.Shape);
        Console.WriteLine("Geometries are equal: {0}", geometriesEqual);
Public Shared Sub RecyclingAppropriateExample(ByVal featureClass As IFeatureClass, ByVal enableRecycling As Boolean)
Using comReleaser As ComReleaser = New ComReleaser()
' Create a search cursor.
Dim featureCursor As IFeatureCursor = featureClass.Search(Nothing, enableRecycling)
' Create a sum of each geometry's area.
Dim feature As IFeature = featureCursor.NextFeature()
Dim totalShapeArea As Double = 0
While Not feature Is Nothing
    Dim shapeArea As IArea = CType(feature.Shape, IArea)
    totalShapeArea + = shapeArea.Area
End While
Console.WriteLine("Total shape area: {0}", totalShapeArea)
End Using
End Sub
Using comReleaser As ESRI.ArcGIS.ADF.ComReleaser = New ESRI.ArcGIS.ADF.ComReleaser()
    Dim t As System.Type = System.Type.GetTypeFromProgID("esriDataSourcesFile.ShorkspaceFactory")
    Dim pWorkspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = CType(Stivator.CreateInstance(t), ESRI.ArcGIS.Geodatabase.IWorkspaceFactory)
    Dim pFeatureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = pWorkspry.OpenFromFile("D:\Workspace\Support\160106-000018", 0)
    Dim pTable As ITable = pFeatureWorkspace.OpenTable("New_dBASE_Table.dbf")
End Using


-プログラミング, ArcGIS
-, , ,

Copyright© WINGFIELD since1981 , 2019 All Rights Reserved.