• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C# .NET fileinfo and file access question

gregulator

Senior member
I have a piece of software that writes to a file when it is done it's own process and I want to know when it is done from my own program. I initially opened the file from a thread and checked if the writing was there but as you can imagine there is a problem when both programs try to access the file. I am now thinking to maybe look at the file write time or size attributes from system.io.fileinfo. Anyone know if I will have any issues with contention this way? Thanks!
 
Why can't the polling program just wait until the processing program finishes with the file and clears its locks? Or you could use named pipes, memory mapped files (shared memory, essentially), a sentinel file (you just look for the presence of the sentinel in a given place, then delete it), a registry key, etc.
 
Originally posted by: gregulator
I have a piece of software that writes to a file when it is done it's own process and I want to know when it is done from my own program. I initially opened the file from a thread and checked if the writing was there but as you can imagine there is a problem when both programs try to access the file. I am now thinking to maybe look at the file write time or size attributes from system.io.fileinfo. Anyone know if I will have any issues with contention this way? Thanks!

You'll have huge problems - you could be dropping in multiple files at the same time which I don't think is going to help you.

Instead of thinking of polling, I'd say take a step back and rethink the logic. It would be more feasible to us an event-delegate model here. Your second thread subscribes to the event and you raise the event from the first thread when the write completes with instance-specific data.
 
Originally posted by: gregulator
I have a piece of software that writes to a file when it is done it's own process and I want to know when it is done from my own program. I initially opened the file from a thread and checked if the writing was there but as you can imagine there is a problem when both programs try to access the file. I am now thinking to maybe look at the file write time or size attributes from system.io.fileinfo. Anyone know if I will have any issues with contention this way? Thanks!

you can monitor external processes or start them, that should be easier than pooling the file
 
Originally posted by: gregulator
...I initially opened the file from a thread and checked if the writing was there but as you can imagine there is a problem when both programs try to access the file. ...

This would work in a *nix environment -- I'm not sure about Windows. It sounds like you have one reader and one writer -- as long as the reader closes the file between polls, everything should be fine.
 
Back
Top