TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Linus Martinsson
NA
9
0
Trouble
Apr 26 2010 4:15 PM
Hey i´m having trouble with some programming in C#. I want to read a file every time it changes.
try
{
using
(
FileStream
file =
new
FileStream
(
@"C:\myFliles\test.txt"
,
FileMode
.Open,
FileAccess
.Read))
{
StreamReader
sr =
new
StreamReader
(file);
string
s =
""
;
while
((s = sr.ReadLine()) !=
null
)
{
if
(sr.EndOfStream)
{
sr.Dispose();
file.Dispose();
sr.Close();
file.Close();
MessageBox
.Show(s);
break
;
}
}
}
}
catch
(
Exception
Ex)
{
MessageBox
.Show(Ex.Message);
}¨
The this code works fine the first time the file changes, but the second time i change the file an exception is raised that says that the file already are in use by another process. How can I solve this problem?
// Linus
Reply
Answers (
8
)
How Do I: Close a SqlDataReader?
what happens when we create an object