如何从当前运行的进程中复制文件 [英] How to copy the file in from the current running process

查看:79
本文介绍了如何从当前运行的进程中复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中从当前正在运行的进程中复制文件.
我遇到的问题是由其他进程使用 "

How to copy the file in from the current running process in c#.
I get the promblem that"used by other process"

推荐答案

如果文件正在由另一个进程使用",则意味着程序已打开文件,但尚未完全关闭文件-结果,您将无法对其进行任何操作.

为了解决这个问题,您能做些什么,首先取决于打开文件的方式.
如果它是外部应用程序,则您将无能为力:例如,某些版本的Outlook会对数据库执行此操作并弄乱备份.
如果它是您的另一个应用程序,则始终打开,阅读,关闭,处置.
如果它是当前应用程序,并且您已经在其他位置打开并读取了文件,但它仍在使用中",则修改您的代码以打开文件,读取文件,将其关闭并显式处理文件流.如果您不这样做,那么在垃圾收集器确定它需要内存空间并处置流之前,可能无法释放该文件.
If a file is "in use by another process" that means that some program has opened the file, but has not fully closed it - as a result, you cannot do anything with it.

What you can do to get around this depends on what is opening the file in the first place.
If it is an external application, you can do very little: some versions of Outlook do this with the database and mess up backups, for example.
If it is another one of your applications, then Open, read, close, dispose at all times.
If it is the current application, and you have opened and read the file elsewhere but it is still "in use" then modify your code to open the file, read it, close it and explicitly dispose of the file stream. If you don''t then the file may not be freed until the garbage collector decides it needs the memory space and disposes of the stream.


这篇关于如何从当前运行的进程中复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆