C# 为什么在windows phone中使用时,无法从关闭的文本阅读器读取
我的Windows phone应用程序中有以下代码,该代码会崩溃,但有一个例外:无法从关闭的文本阅读器读取 有人能告诉我为什么吗?我不知道怎么了C# 为什么在windows phone中使用时,无法从关闭的文本阅读器读取,c#,silverlight,windows-phone-7,C#,Silverlight,Windows Phone 7,我的Windows phone应用程序中有以下代码,该代码会崩溃,但有一个例外:无法从关闭的文本阅读器读取 有人能告诉我为什么吗?我不知道怎么了 IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication(); IsolatedStorageFileStream FS = ISF.OpenFile("ipview.txt", FileMode.Open, FileAcc
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());
});
}
}
关闭
StreamReader
后,此代码在调度程序线程上执行:
Dispatcher.BeginInvoke(() =>
{
IPHistoryBox.Items.Add(SR.ReadLine());
});
更改如下:
var x = SR.ReadLine();
Dispatcher.BeginInvoke(() =>IPHistoryBox.Items.Add(x));
这样,在当前线程上读取StreamReader
,并在Dispatcher线程上使用结果