• C# The process cannot access the file because it is being used by another process


    C# The process cannot access the file because it is being used by another process

     
    The process cannot access the file because it is being used by another process.
    This error message is mostly comes up,
    when you try to access a file which is opened by another process.

    You may open an image file in one of your form in a picturebox with usingImageFromFile or something.
    I mostly use memorystream to open an image.
    After read it in byte[] write it into a stream and close it.

    You can check whether a file is being used or not with a simple function.
    Try to open a file with none share.
    public bool IsFileUsedbyAnotherProcess(string filename)
     {
     try
     {
      File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.None);
    }
    catch (System.IO.IOException exp)
    {
    return true;
    }
    return false;
     
    }

    This function will return true if
    the file because it is being used by another process or not.
  • 相关阅读:
    chrome被篡改 导航到搜狗 或者特殊页面
    安装tomcat jdk
    监控tomcat 启动
    关于如何关闭445端口
    python模拟大数据登陆
    搭建vsftpd服务
    kali syn洪水攻击实例
    HP880G3 安装RHEL6.5
    Python_列表
    Python第一个请求接口
  • 原文地址:https://www.cnblogs.com/mschen/p/5353843.html
Copyright © 2020-2023  润新知