zoukankan      html  css  js  c++  java
  • AO解锁shp文件

    AO开发中加载shp文件后,无论删除对象还是垃圾回收都不能解除shp文件的锁定,导致在其他地方无法对该图层进行操作,只有关闭应用程序才能删除加锁文件,彻底释放资源。

    其实,AO中有专门的代码解除资源锁定,解锁文件:

    1、存在接口IWorkspaceFactory的情况

    IWorkspaceFactory pwf = new ShapefileWorkspaceFactory();
    //关闭资源锁定   
    IWorkspaceFactoryLockControl ipWsFactoryLock = (IWorkspaceFactoryLockControl)pwf;
    if (ipWsFactoryLock.SchemaLockingEnabled)
    {
        ipWsFactoryLock.DisableSchemaLocking();
    }


    2、仅已知接口IFeatureClass的情况

    /// <summary>
    /// 解锁IFeatureClass锁定的资源
    /// </summary>
    /// <param name="pFeatureClass">锁定资源的要素类</param>
    /// <param name="releaseComObject">false-默认,不释放要素类;true-解锁并释放要素类</param>
    public static void UnlockResource(IFeatureClass pFeatureClass, bool releaseComObject = false)
    {
        if (pFeatureClass == null) return;
        IWorkspace pWorkspace = ((IDataset)pFeatureClass).Workspace;
        if (pWorkspace == null) return;
        //关闭资源锁定
        try
        {
            IWorkspaceFactoryLockControl ipWsFactoryLock = (IWorkspaceFactoryLockControl)pWorkspace.WorkspaceFactory;
            if (ipWsFactoryLock != null && ipWsFactoryLock.SchemaLockingEnabled)
                ipWsFactoryLock.DisableSchemaLocking();
            if (releaseComObject)
                ComReleaser.ReleaseCOMObject(pFeatureClass);
        }
        catch (Exception ex)
        {
        }
    }
  • 相关阅读:
    linux系统 ssh免密码登录服务器主机
    QPS TPS 并发数 响应时间
    mysqlmtop开源系统监控mysql数据库性能
    jenkins 自动化构建 部署 回滚配置
    实用Linux命令记录
    关于高并发的几个基础问题
    tcp四次挥手
    时序数据异常检测相关的问题记录
    判断时序数据的周期性
    最短路径问题
  • 原文地址:https://www.cnblogs.com/publiter/p/14431564.html
Copyright © 2011-2022 走看看