I have a writing process on C++ application, another C# application reads data continuously whenever the file has been changed.
On C++:
FILE *fp = fopen(result_file, "a");
if (fp) {
// Write some thing
fclose(fp);
}
On C#:
private void Init() {
FileSystemWatcher watcher = new FileSystemWatcher(ResultFolder);
watcher.Changed += new FileSystemEventHandler(OnResultChanged);
watcher.EnableRaisingEvents = true;
}
private void OnResultChanged(object sender, FileSystemEventArgs e) {
if (e.ChangeType == WatcherChangeTypes.Changed) {
// Check file ready to read
// Ready all lines
string[] lines = File.ReadAllLines(e.FullPath);
// Process lines
}
}
But sometimes the code on C++ cannot open the file to read, how can I fix it?
P/S: I found that on C# we have a way to share file access such as below command
File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
But cannot find similar way in C++.