• 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)
        {
        }
    }
  • 相关阅读:
    奥多朗WIFI 插座
    USB2.0的最高传输速率
    Win10各个版本免费激活密钥
    LINUX API函数大全
    COLLECTL LINUX 监控
    打印机工作原理
    深入理解windows系统内的GMT和时区
    searchIndexer.exe占用过高CPU
    systemtap 作用-- SystemTap使用技巧
    ADSL和ITV
  • 原文地址:https://www.cnblogs.com/publiter/p/14431564.html
Copyright © 2020-2023  润新知