Can a Stream notify other objects when it has been changed?

  • Thread starter Thread starter Peter Rilling
  • Start date Start date
P

Peter Rilling

Is there anyway of being notified when a Stream is modified? Basically, If
one of my objects is passed a stream, I would like to initialize an object
cache. Then when the Stream changes, I would like to update the cache.
Does not look like the stream has any event that I can hook.
 
Peter,

No, there is no way to do this, and if there was, then I would be
worried. Not all streams support seeking on the stream, so for something
like a network connection, this would be a problem.

What you want to really do, IMO, is to find out if the store that the
stream represents (db, network, file, etc, etc) has changed, and if it has,
get a new stream.

Hope this helps.
 
How can I determing if the stream has changed? Is some other object changes
a byte in the middle of the stream, how can I be notified of this?

Nicholas Paldino said:
Peter,

No, there is no way to do this, and if there was, then I would be
worried. Not all streams support seeking on the stream, so for something
like a network connection, this would be a problem.

What you want to really do, IMO, is to find out if the store that the
stream represents (db, network, file, etc, etc) has changed, and if it has,
get a new stream.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peter Rilling said:
Is there anyway of being notified when a Stream is modified? Basically, If
one of my objects is passed a stream, I would like to initialize an object
cache. Then when the Stream changes, I would like to update the cache.
Does not look like the stream has any event that I can hook.
 
Peter Rilling said:
How can I determing if the stream has changed? Is some other object changes
a byte in the middle of the stream, how can I be notified of this?

You could wrap the existing stream in your own stream, which forwards
on all methods to the other stream, but raises an event every time a
write occurs.
 
Back
Top