This usually happens when you execute that code block several times concurrently. You end up locking the file. So, you have to make sure you include FileAccess and FileShare modes in your constructor like this:
using (var isoStream = new IsolatedStorageFileStream("Notes.xml", FileMode.Open, FileAccess.Read, FileShare.Read, isolatedStorage)
{
//...
}
If you want to write to the file while others are reading, then you need to synchronize locking like this:
private readonly object _readLock = new object();
lock(_readLock)
{
using (var isoStream = new IsolatedStorageFileStream("Notes.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, isolatedStorage)
{
//...
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…