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.

C# The process cannot access the file because it is being used by another process的更多相关文章

  1. FileStream:The process cannot access the file because it is being used by another process

    先看下面一段代码(先以共享的方式打开文件读写,然后以只读的方式打开相同文件): FileStream fs  = new FileStream(filePath, FileMode.Open, Fil ...

  2. the process cannot access the file because it is being used by another process

    当在IIS中改动绑定的port号后启动时遇到例如以下错误,表明你的port号已经被占用了 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdmljMDIyOA ...

  3. Go-The process cannot access the file because it is being used by another process.

    where? Go程序在读取文件时候 why? 因为有其他进程也在读取和Go程序想要读取的文件,参数冲突 way? 关闭其他程序进程对该文件的读取操作

  4. Solution: The process cannot access the file [filename] because it is being used by another process.

    http://www.brianstevenson.com/blog/solution-the-process-cannot-access-the-file-filename-because-it-i ...

  5. 自定义容器启动脚本报错:exec user process caused "no such file or directory"

    创建容器起不来,一直是restarting状态,查看容器的报错日志如下: standard_init_linux.go:178: exec user process caused "no s ...

  6. HDFS relaxes a few POSIX requirements to enable streaming access to file system data

    https://hadoop.apache.org/docs/r2.7.2/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html Introduction [ ...

  7. use tomcat to access the file cross the environment

    background: 项目中的一个小工具,是一个Cron Job ,每天去搜集下服务器Hadoop Job的运行状态,并生成一份报告发送给整个Team,生产报告的同时把相关的日志文件保存到固定的一台 ...

  8. Microsoft Office Excel cannot access the file, There are several possible reasons

    今天在做EXCEL打印读取模板时报错了,错误信息如下: Microsoft Excel cannot access the file 'D:\xx.xlsx'. There are several p ...

  9. The process could not read file xxx due to OS error 53

      在不同地域的两个SQL Server服务器上配置了复制(Replication)用于同步数据(生产环境配置有Replication,测试环境也配有Replication),两地通过专线连接起来,这 ...

随机推荐

  1. [C++]C++中的运行时类型检测

    Date:2014-1-3 Summary: 使用C++中的运行时类型检测.(文章重点在于记录本人的使用情况,并非深层讨论RTTI) Contents:写习惯C#的我,在C++依然存在哪些.NET的惯 ...

  2. nohup sort -k1 -n -t$'\t' ./bigfile.16 -o./test/bigfile.16.ok &

    nohup sort -k1 -n -t$'\t' ./bigfile.16 -o./test/bigfile.16.ok &

  3. GNU libmicrohttpd 0.9.29 发布 - 开源中国社区

    GNU libmicrohttpd 0.9.29 发布 - 开源中国社区 GNU libmicrohttpd 0.9.29 发布

  4. Android开发 - ActivityLifecycleCallbacks用法初探

    ActivityLifecycleCallbacks是什么? Application通过此接口提供了一套回调方法,用于让开发人员对Activity的生命周期事件进行集中处理. 为什么用Activity ...

  5. hdu2639(背包求第k优解)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:给出一行价值,一行体积,让你在v体积的范围内找出第k大的值 分析:dp[i][j][k]表 ...

  6. 移动开发平台-应用之星app制作教程

    目前在AppStore.GooglePlay等应用商店里已经有以百万计的Apps,应用程序使移动互联网空间得以无限拓展.很多人梦想着AngryBirds式的奇迹在自己身上发生,他们渴望自己开发的应用程 ...

  7. Gnu Linux--Ubuntu系统清理项整理

    /*********************************************************************  * Author  : Samson  * Date   ...

  8. Learning Cocos2d-x for WP8(9)——Sprite到哪,我做主

    原文:Learning Cocos2d-x for WP8(9)--Sprite到哪,我做主 工程文件TouchesTest.h和TouchesTest.cpp 相关素材文件 事件驱动同样适用于coc ...

  9. JAVA邮件收发实现(待)

    http://blog.csdn.net/ycg01/article/details/1394465

  10. linux下执行strlwr函数出错:ld returned 1 exit status

    执行strlwr函数时报错.源程序例如以下: #include<stdio.h> #include<string.h> void main() { char s[10]={&q ...