adf for dotnet中servercontext的释放

当使用local数据源做adf开发的时候,就可能接触到serverconttext,获取方法是MapResouceLocal.ServerContextInfo.ServerContext。

IServerContext对应的就是ArcServer上的用来处理请求的一个soc.exe进程。在esri的帮助文档中有这样一段话

When your application is finished working with a server context, it must release it back to the server by calling the ReleaseContext method. If you allow the context to go out of scope without explicitly releasing it, it will remain in use and unavailable to other applications until it is garbage collected. Once a context is released, the application can no longer make use of any objects in that context. This includes both objects that you may have obtained from the context or objects that you created in the context.

对于ArcServer的NoPooled的情况应该是在不再使用(如用户退出登录)的时候释放IServerCotnext。

下面主要讨论Pooled的情况,现在怕也没人用NoPooled这种方式了。

一、所以需要每次处理http请求的最后释放掉ServerContext,但在开发的时候(比如写一个tool)发现,当http在处理请求的时候,确实占用了一个ServerContext(使用arcserver提供的webmanager可以看到当前正在使用的Instance及servercontext数量),但我们并没有在代码中释放ServerContext,可处理完请求后,发现ServerContext还是释放掉了。那肯定是adf框架自己帮我们释放掉了,查看源代码发现GISResourceManager<T, R>.Dispose方法,该方法又调用了DataSourceManager.Dispose方法,在该方法中调用了IGISResourceIGISFunctionality的Dispose方法,对于local连接,MapResourceLocal.Dispose方法中释放了ServerContext。

二、如果自己连接ArcServer,通过IServerObjectManager.CreateServerContext创建的ServerContext需要自己写代码释放,最好是用完就释放。

三、如果页面写了一个ajax请求,而这个ajax请求就是一般的asp.net ajax请求(没有用adf提供的ajax方法请求,及没有通过Map控件来处理请求),如果在处理这个ajax请求时用到了ArcServer的远程对象,这个时候必须要自己写代码来释放ServerContext。为什么会出现这种情况呢,原来GISResourceManager<T, R>.Dispose方法会判断它自己是否initialed,如果没有则不会执行释放操作:

if (this.m_initialized || base.m_atLeastOneResourceInitialized) {

this.OnResourcesDispose(null);

base.DataSourceManager.Dispose();

this.m_initialized = false;

base.m_atLeastOneResourceInitialized = false; }

而无论是加载整个页面还是,通过Map控件来处理ajax请求,查看GISResourceManager.Initialized属性均为True,而自己实现一个asp.net ajax请求时,该属性为False。

posted on 2011-10-28 17:28  漫步人生  阅读(653)  评论(0编辑  收藏  举报