检查文件是否在C#,.NET中写入完成 [英] Check file is writing complete or not in C#, .NET

查看:110
本文介绍了检查文件是否在C#,.NET中写入完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个系统需要处理以下场景



01.System one正在将文本写入共享位置的文件中。我们不知道该系统是如何编写的。



02.我们需要编写c#程序,应该只从共享位置复制完成的文件。



现在问题是我应该如何检查文件是否完整。系统一可能是将数据写入我正在处理的文件中?



我尝试过的方法:



c#program无法检测文件是否在记事本或记事本中打开++

I have 2 systems need to handle below scenario

01.System one is writing text into file at shared location. we are not aware about that system how its writing.

02. We need to write c# program should copy only completed file from shared location.

now problem is how should i check the file is complete or not . system one might be writing data into file which i am coping?

What I have tried:

c# program is not able to detect if file is open in notepad or notepad++

推荐答案

首先,请阅读我对该问题的评论...



如果在读/写操作期间没有锁定文件的进程,则无法确定特定文件是已完成还是否已完成。但是......



有一个 FileSystemWatcher类(System.IO) [ ^ ],它正在侦听文件系统更改通知,并在目录或目录中的文件发生更改时引发事件。请参阅以下列表: FileSystemWatcher Events(System.IO) [ ^ ]



祝你好运!
First of all, please read my comment to the question...

If there's no process which locks file during read/write operation, there's no chance to find out if specific file is "completed" or no. But...

There's a FileSystemWatcher Class (System.IO)[^], which is listening for file system change notifications and raises events when a directory, or file in a directory, changes. See the list of: FileSystemWatcher Events (System.IO)[^]

Good luck!


这篇关于检查文件是否在C#,.NET中写入完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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