文件系统监视程序IOException [英] FileSystemWatcher & IOException

查看:111
本文介绍了文件系统监视程序IOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在实现FileSystemWatcher类时,我遇到了一个小问题.我有一个文本文件,该文件正在监视"我.文件更改后,我的应用程序将新行吐出到表单中.这可以工作,但是在不带断点的情况下运行它时,我往往会得到一个IOException.我打开了文本文件,此刻正在手动进行更改.当我必须读取文本文件以获取行数和新行信息时,就会出现问题.

我处理此IOException的正确方法是什么?我可以使用某种形式的等待命令(我不能错过任何行更新),还是有一种更强大的方法来解决此问题?



您的时间和帮助将不胜感激.

丹科,

Jib.

Hi all,

I''ve got myself a little problem whilst implementing the FileSystemWatcher Class. I have a text file that it is "watching" for me. When the file changes I have my app spit out the new line to my form. This works, but I tend to get an IOException when I run it without breakpoints in. I have the textfile open and am making changes manually at the moment. The problem arises when I have to read the textfile to obtain the number of lines and the new line information.

What''s the correct way for me to handle this IOException? Can I use some form of wait command (I can''t afford to miss a line update), or is there a more robust way to deal with this problem?



Your time and help will be greatly appreciated.

Danke,

Jib.

推荐答案

我只是在猜测,因为您没有提供异常消息,但是听起来您正在写文件的同时正在打开文件仍然打开.

修改您的代码,使其重试文件操作.如果出现异常,请等待一两秒钟,然后返回并重试.您还可能希望在其中内置救助,因为您可能不想永远尝试相同的操作.如果由于某种原因该文件根本不可用,则必须有一条出路.
Im just guessing because you didn''t supply the exception message, but it sounds like you''re opening the file while the process that is writing to it still has it open.

Modify your code so that it retrys the file operations. If it gets an exception, wait a second or two and go back and try it again. You''ll also want a bailout built into this since you probably don''t want to your trying the same operation forever. There has to be a way out if the file isn''t available at all for some reason.


文件更新得非常频繁,所以我必须实现一个计时器来检查滴答频率为1.我复制原始文件,然后只处理复制的文件,所以我不会打断原始文件. -1秒钟前的吉布罗尼(Jibrohni)
The file is getting updated very frequently so I had to implement a timer that checked it with a tick frequency of 1. I copy the original file and just deal with the copied file so I don''t interrupt the original. - Jibrohni 1 sec ago


这篇关于文件系统监视程序IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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