On the ball is a file with DateTime
.
On different servers, spinning 2 (or more) instances of the same application that access the file on the ball, take time from it and record the new time.
I use
using (var fs = new FileStream(dateFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
And then I read the time and try to overwrite the new time with
using (var sw = new StreamWriter(fs))
But such use leads to writing , rather than overwriting the file.
How to organize exclusive access to a file so that no one else can read information from it (and even more so)?
How to overwrite a file? (Here you probably need to use
fs.Seek(0, SeekOrigin.Begin)
and without using theStreamWriter
class)