D
Dan Kelley
We have a multithreaded app that responds to events, and writes these
events to a text file. This text file is used by an external system
for further processing.
We want to be able to write multiple entries to the file, and then
rename it and copy it to a new location when the file reaches a
certian size, or a certain time span elapses (which ever comes first).
I have created a static/shared timer member variable in class that
writes to the file. When the file is written to, I check the size of
the file. If it is greater than the limit a funtion is called to
rename the file, and the timer is "reset".
My question is, in a multithreaded environment, how do I detect if the
file is being written to in the event the timer fires at the same time
and tries to rename the file. I could swallow the IO exception, sleep
for a while, and try again, but this cannot be the best solution.
Anyone have any ideas?
Thanks
Dan
events to a text file. This text file is used by an external system
for further processing.
We want to be able to write multiple entries to the file, and then
rename it and copy it to a new location when the file reaches a
certian size, or a certain time span elapses (which ever comes first).
I have created a static/shared timer member variable in class that
writes to the file. When the file is written to, I check the size of
the file. If it is greater than the limit a funtion is called to
rename the file, and the timer is "reset".
My question is, in a multithreaded environment, how do I detect if the
file is being written to in the event the timer fires at the same time
and tries to rename the file. I could swallow the IO exception, sleep
for a while, and try again, but this cannot be the best solution.
Anyone have any ideas?
Thanks
Dan