YouTube | Facebook | X(Twitter) | RSS

ManageLifetime を使用する方法

2016/9/1 (木)

ArcObjects のオブジェクトを開放するのに ManageLifetime を使用する方法

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

using ステートメント

public static void RecyclingInappropriateExample(IFeatureClass featureClass, Boolean
    enableRecycling)
{
    using(ComReleaser comReleaser = new ComReleaser())
    {
        // Create a search cursor.
        IFeatureCursor featureCursor = featureClass.Search(null, enableRecycling);
        comReleaser.ManageLifetime(featureCursor);

        // 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)
comReleaser.ManageLifetime(featureCursor)

' 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\", 0)

    Dim pTable As ITable = pFeatureWorkspace.OpenTable("New_dBASE_Table.dbf")

    comReleaser.ManageLifetime(pTable)
    comReleaser.ManageLifetime(pFeatureWorkspace)
    comReleaser.ManageLifetime(pWorkspaceFactory)

End Using

関連記事

  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

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

WINGFIELD since1981をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む