Groups | Blog | Home
all groups > c# > march 2004 >

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


Peter Rilling
3/1/2004 10:56:38 PM
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.

Nicholas Paldino [.NET/C# MVP]
3/2/2004 12:00:38 PM
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]
- mvp@spam.guard.caspershouse.com

[quoted text, click to view]

Peter Rilling
3/2/2004 4:19:14 PM
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 [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:OTqBkgHAEHA.3056@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Jon Skeet [C# MVP]
3/3/2004 8:45:31 AM
[quoted text, click to view]

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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button