异常时,使用FileIO.ReadTextAsync的文件中读取文本 [英] Exception when reading text from the file using FileIO.ReadTextAsync

查看:472
本文介绍了异常时,使用FileIO.ReadTextAsync的文件中读取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用读取LOCL文本文件时,出现以下异常

  VAR文本=等待FileIO.ReadTextAsync(文件); 




与此机会锁是相关的已关闭的句柄。的
操作锁定现破裂。 (异常来自HRESULT:0x80070323)




这发生在回归单元测试之一,它也时有发生的时间在应用程序。应用程序是XAML + C#



任何想法可能会导致它?!


解决方案

我有同样的问题,即由途中发生线程同意。我试图接取两地相同的文件在同一时间,并没有意识到这一点。



尝试验证您的代码中的另一个接取寻找一些相同的文件,并确认,如果你关闭后读它,不要忘记叫等待,或在每个文件读取使用锁。我认为它可以解决您的问题。


I am getting the following exception when attempting to read a locl text file using

var text = await FileIO.ReadTextAsync(file);

The handle with which this oplock was associated has been closed. The oplock is now broken. (Exception from HRESULT: 0x80070323)

This happens in one of the regression unit tests, it also happens from time to time in the app. App is XAML + C#

Any ideas what might be causing it?!

解决方案

I was having the same problem, that ocurred by concurrence threading. I was trying to acess the same file in two places at the same time and didn't realize it.

Try to verify your code looking for some another acess to the same file and verify if you are closing after read it, and don't forget to call "await" or use a lock in every file reading. I think it may solve your issue.

这篇关于异常时,使用FileIO.ReadTextAsync的文件中读取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆