I have the following code in my Windows phone application, that crashes with the exception: Cannot read from a closed TextReader.
Can someone tell me why, I cant figure out whats wrong.
IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream FS = ISF.OpenFile("ipview.txt", FileMode.Open, FileAccess.Read);
using (StreamReader SR = new StreamReader(FS))
{
while (!SR.EndOfStream)
{
Dispatcher.BeginInvoke(() =>
{
IPHistoryBox.Items.Add(SR.ReadLine());
});
}
}
This code is executed on the dispatcher thread after the
StreamReaderis closed:change it like this:
This way the
StreamReaderis read on the current thread and the result is used on the Dispatcher thread.