3echo

心有多大,世界便有多大!
  博客园  :: 首页  :: 联系 :: 订阅 订阅  :: 管理

ArcGIS Server笔记之ManageLifetime

Posted on 2006-04-12 12:57  3echo  阅读(859)  评论(2编辑  收藏  举报

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)