How can I generate notifications that the data recorded using FileStream is on disk?

I would like to read the file after I was notified that a certain amount of data was written to it through another stream.

My main attempt was to create an active topic in my Writer class, call OnNext after writing to the BinaryWriter that it is composed with. This BinaryWriter uses a FileStream. This does not seem to work. I assume that I am not guaranteed that the recording was reddened.

I would prefer not a manual flash call. Is there any way to do this?

+6
source share
1 answer

On a broader level, you are asking about the relationship between threads. There are several ways to handle this, depending on your preferences and environment.

If you have not done so already, check out the POSIX streams here and here . Check out the sections on conditional variables or semaphores.

The .NET Framework has a System Threading library, which is also worth a look. In particular, it has both a semaphore and a monitor class. In this case, you may need one or the other solution.

Finally, consider the InotifyPropertyChanged interface and / or events. In this context, this is an alternative way to signal progress from the reader.

In general, I would recommend that your writer thread provide a notification of an event change or generate a semaphore after writing X bytes. From there, the reader will either catch the event or follow the semaphore and act accordingly.

I suspect that the monitor class will not be as useful to you as blocking is likely to prevent concurrent access to the file.

+1
source

Source: https://habr.com/ru/post/944644/


All Articles