I
intrepid_dw
All:
I have a .NET 1.1 C#-based WinForms application that, as part of its
normal operation, creates and updates an XML-based log file. I expose a
method from a class to retrieve the text of the file via a
StringReader, which then puts the text into a DataView that is bound to
a DataGrid. This all works terrifically.
In testing the program, I discovered certain situations in which
activities were written to the log file at unexpected times and were
thus not updated to the UI. Rather than try to determine all the points
at which a change to the log file might occur that I might have missed,
I opted to spin off a thread to monitor the log file, with the intent
of refreshing the DataView upon each change notification.
I used a FileSystemWatcher to notify the thread of change events on the
file, and therein starts my problem. When I start the application, and
perform an action that gets logged, the notification occurs, but when I
go to fetch the updated text from the file I get an "IOException - File
is in use by another process."
Now perhaps my understanding of FileSystemWatcher semantics is naive or
incorrect, but the behavior almost makes me believe the FSW is actually
holding a *lock* on the file, which to me would be counterintuitive for
a "watcher" process. Up to the point of the failure, the application is
working - event occurs, log is written, notification fires, and the
call is made to retrieve the updated log text - and that's what
crashes.
If my understanding of how FSW works is wrong, or if this is such a
naive problem that I should have found another answer by more diligent
searching, my apologies in advance. (The problems I did find that
seemed similar actually departed in certain important ways) Any
thoughts or suggestions to resolve the problem would be appreciated.
-intrepid
I have a .NET 1.1 C#-based WinForms application that, as part of its
normal operation, creates and updates an XML-based log file. I expose a
method from a class to retrieve the text of the file via a
StringReader, which then puts the text into a DataView that is bound to
a DataGrid. This all works terrifically.
In testing the program, I discovered certain situations in which
activities were written to the log file at unexpected times and were
thus not updated to the UI. Rather than try to determine all the points
at which a change to the log file might occur that I might have missed,
I opted to spin off a thread to monitor the log file, with the intent
of refreshing the DataView upon each change notification.
I used a FileSystemWatcher to notify the thread of change events on the
file, and therein starts my problem. When I start the application, and
perform an action that gets logged, the notification occurs, but when I
go to fetch the updated text from the file I get an "IOException - File
is in use by another process."
Now perhaps my understanding of FileSystemWatcher semantics is naive or
incorrect, but the behavior almost makes me believe the FSW is actually
holding a *lock* on the file, which to me would be counterintuitive for
a "watcher" process. Up to the point of the failure, the application is
working - event occurs, log is written, notification fires, and the
call is made to retrieve the updated log text - and that's what
crashes.
If my understanding of how FSW works is wrong, or if this is such a
naive problem that I should have found another answer by more diligent
searching, my apologies in advance. (The problems I did find that
seemed similar actually departed in certain important ways) Any
thoughts or suggestions to resolve the problem would be appreciated.
-intrepid