Reputation: 25601
My question has already kind of been asked at Releasing underlying Stream returned by Application.GetResourceStream on WP7, but I have a couple variations on the question:
using
block on a stream reader built on top of the stream.Here's some code:
System.Windows.Resources.StreamResourceInfo ri =
App.GetResourceStream(new Uri("Resources/Idioms.txt", UriKind.Relative));
using (System.IO.StreamReader sr = new System.IO.StreamReader(ri.Stream))
{
idioms = sr.ReadToEnd().Split(lineSeps, StringSplitOptions.RemoveEmptyEntries);
}
Now StreamReader's close method (which I assume is the method that implements IDisposable.Dispose
) indicates that it also closes the underlying stream (which I assume is also implementing IDisposable.Dispose
).
So is this closing or disposing of the IO.Stream
object provided by GetResourceStream
's Stream
property:
(Should I use or avoid using
on the reader built on top of the stream?)
Upvotes: 0
Views: 192
Reputation: 33738
StreamReader
's ctor has an overload that lets you tell it to keep the stream from being closed.
Also, you have it slightly backwards (unless I misunderstood). It's the Dispose
method that calls Close
, not the other way around.
Upvotes: 1