我有一个音频文件存储在IsolatedStorage
..
我想通过调用另一个类的方法来访问它:
using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = isolatedStorage.OpenFile(filePath, FileMode.Open, FileAccess.Read))
{
return fileStream;
}
}
现在,当我以这种方式调用该方法时:
var fileStream = Musics.TryGetMusic("DaDaDa.mp3");
musicMediaElement.SetSource(fileStream);
musicMediaElement.Play();
我收到一条错误消息,说它无法读取已关闭的文件。
原因是我正在使用using
语句,并且在调用时文件已关闭Play()
。我怎么解决这个问题?
这是因为,我想你叫它,就像
....
using (IsolatedStorageFileStream fileStream = isolatedStorage.OpenFile(filePath, FileMode.Open, FileAccess.Read))
{
return fileStream;
}
....
从using
语句退出后,fileStream
实例将被处置。
解决此问题应该足以在using
这里不使用,而要跟踪该实例的生存期并在适当的地方手动调用处置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句