StreamReader检查更新! [英] StreamReader Checking for updates!

查看:97
本文介绍了StreamReader检查更新!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在A-level完成第一年后。这个假期我试图编写许多不同的东西。试图扩大我的知识!



我昨晚想到msn或facebook这样的应用程序如何围绕消息传递方面工作。我试着创建一个两个人可以用来互相交流的应用程序! (虽然读取文件并保存文件)





我有一个间隔为1秒的计时器。每个刻度我会开始一个streamreader读取行并关闭。



编辑文件添加不同的行我可以保存,大部分时间它都可以正常工作。该程序将能够读取数据并显示它。 (暂时通过记事本完成)



虽然有时候在尝试保存文件时会看到它被另一个进程使用。有没有更好的方法来做这个基本的程序。我可以使用'尝试',但这太容易了。高级程序员将如何克服这个问题?谢谢!



P.S我的第一个问题! Code Project是一个非常好的网站!



总结的问题:

更新文本文件,同时已在另一个文本文件中查看。

After finishing year one at A-level. This holiday I have tried to code many different things. Trying to widening my knowledge!

I was thinking last night how applications such as msn or facebook work around the messaging side. I was to try and create an app that two people could use to talk to one another!. (though reading a file and saving the file)


I had a timer with an interval of 1 second. Every tick I would start a streamreader read the lines and close.

Editing the file adding different lines I could save and most of the time it would work fine. The program would be able to read the data and display it. (done through notepad, for the time being)

Though sometimes when trying to save a file it would see that its being used by another process. Is there a better way of doing this basic program. I could use a 'try' but that's too easy. How would an advanced programmer get over this? Thank you!

P.S My first question! Code Project is quite a nice website!

Summarised question:
Updating a text file, while already being viewed in another.

推荐答案

尝试和捕获是最简单的方法

否则,当您知道文件正在使用时,您可能能够做其他事情(即创建)另一个文件,并在完成后删除它)所以另一个实例可以检查文件是否存在



或者你可以通过注册表...或其他任何方式。您可以将其设置为您想要的复杂或简单:D
try and catch is the easiest way
Otherwise you might be able to do something else when you know the file is in use (ie. create another file and delete it when done) so the other instance can check if the file exists

Or you can do it through registry... or whatever. You can make it as complex or as simple you want :D


这篇关于StreamReader检查更新!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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