在使用多线程的时候,经常会报错OpenFile Operation not permitted on IsolatedStorageFileStream,原因是IsolatedStorageFile和IsolatedStorageFileStream在多线程中被多处调用而出现不可预知的内存崩溃,此时需要进行加锁,代码如下:

 private static readonly object _readLock = new object(); 
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { //Open existing file lock (_readLock) { using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("log.txt", FileMode.Append, myIsolatedStorage)) using (StreamWriter writer = new StreamWriter(fileStream)) { string someTextData = "\r\n" + DateTime.Now + "-----------" + message; writer.Write(someTextData); } }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-27
  • 2022-12-23
  • 2022-01-14
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案