zoukankan      html  css  js  c++  java
  • ArcGIS Server笔记之ManageLifetime

    ArcGIS Server笔记之ManageLifetime


        ManageLifetime:
    从字面意思我们理解为“生命周期管理”。生命周期应该有一个范围,也就是一个作用域吧。在这个作用域范围生命存在,超出这个范围生命终止(个人理解)。

    Use the ManageLifetime method to add your COM object to the set of objects that will be explicitly released when the WebObject is disposed.

    WebObject析构时,使用ManageLifetime方法管理的一系列创建的COM对象将被显示释放。

    When you scope the use of WebObject within a using block, any object (including your cursor) that you have added to the WebObject using the ManageLifetime method will be explicitly released at the end of the using block.

    当你使用Using语句块管理WebObject对象时,WebObject对象的ManageLifetime方法管理的任何COM对象在Using语句块结束后都将被显示释放。

    示例代码:
        

     1  private void doSomthing_Click(object sender, System.EventArgs e)
     2  {
     3    using (WebObject webobj = new WebObject())
     4    {
     5      ServerConnection serverConn = new ServerConnection("doug"true);
     6      IServerObjectManager som = serverConn.ServerObjectManager;
     7
     8      IServerContext ctx = som.CreateServerContext("Yellowstone","MapServer");
     9      IMapServer mapsrv = ctx.ServerObject as IMapServer;
    10      IMapServerObjects mapo = mapsrv as IMapServerObjects;
    11      IMap map = mapo.get_Map(mapsrv.DefaultMapName);
    12
    13      IFeatureLayer flayer = map.get_Layer(0as IFeatureLayer;
    14      IFeatureClass fclass = flayer.FeatureClass;
    15
    16      IFeatureCursor fcursor = fclass.Search(nulltrue);
    17      webobj.ManageLifetime(fcursor);
    18
    19      IFeature f = null;
    20      while ((f = fcursor.NextFeature()) != null)
    21      {
    22        // do something with the feature
    23      }

    24
    25      ctx.ReleaseContext();
    26    }

    27  }

     

    备注

    1using 语句:

    using 语句中创建一个实例,确保退出 using 语句时在对象上调用 Dispose。当到达 using 语句的末尾,或者如果在语句结束之前引发异常并且控制离开语句块,都可以退出 using 语句。

    2WebObject.ManageLifetime 方法   [C#]

    public void ManageLifetime(object o);

    参数:o  Com对象

    3WebObject对象:

    命名空间: ESRI.ArcGIS.Server.WebControls

    程序集: ESRI.ArcGIS.Server.WebControls (in ESRI.ArcGIS.Server.WebControls.dll)

     

  • 相关阅读:
    GET POST方法长度限制(转)
    解决Android LogCat 输出乱码的问题(转)
    Supported Values for @SuppressWarnings(转)
    Gson通过借助TypeToken获取泛型参数的类型的方法(转)
    使用GSON和泛型解析约定格式的JSON串(转)
    HDU 4423 Simple Function(数学题,2012长春D题)
    VIM简单配置(windows)
    LightOJ 1074
    HDU 4763 Theme Section (2013长春网络赛1005,KMP)
    HDU 4764 Stone (2013长春网络赛,水博弈)
  • 原文地址:https://www.cnblogs.com/3echo/p/373141.html
Copyright © 2011-2022 走看看