Reputation: 31878
I'm trying to implement a network protocol class with an interface similar to WebRequest specifically with the input stream returned by GetRequestStream, however I am having difficulty determining when the request stream is complete, as it does not have any events (disposing, etc).
How can I monitor a Stream to determine when it is Closed/Disposed? Is my only choice to wrap it in a class that implements Stream?
In particular I'm implementing FTP with some features that the FtpWebRequest does not (SITE
, ALLOC
, etc). I need to know when the data stream is closed/complete so I can check the command stream for a success or error message.
Upvotes: 4
Views: 2835
Reputation: 81700
I believe the reason stream does not provide an event for disposing/closing is that the only person needs to know is the owner of it - and the owner would call it itself.
Disposing a stream must be an explicit operation hence an event would not make much sense. Having said that, owner of the stream can expose an event and inform its clients about Operation ending.
Also having an event means that the stream can be shared among multiple clients which again I believe is not a good practice.
Upvotes: 3