惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
C
Check Point Blog
V
V2EX
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
A
About on SuperTechFans
D
DataBreaches.Net
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
博客园_首页
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 漫步人生

c# 使用GetOleDbSchemaTable获取access数据库结构 xp上vs2010+IE8无法调试脚本 iis 上部署asp.net程序出错排查 windows2008的共享 使用sqlite绿色部署问题 在vs中使用正则表达式 事件不应该有返回值 ae的com对象在dotnet中的释放问题 修改Windows中ASPNET账户的密码 ae显示arcserver的地图服务 arcgis 编辑时独占mdb adf for dotnet中动态给ArcGis Server服务添加图层 js中在不知道属性名时获取属性对象 html文档中的name属性 ie中js a光标位置 adf中UpdatePanel刷新地图 windows局域网内以arcgis server local的方式连接arcserver服务器 c#与 如何调试 C#与C/C++的互操作
adf for dotnet中servercontext的释放
漫步人生 · 2011-10-28 · via 博客园 - 漫步人生

当使用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。