windows-8 – 在winrt中访问文件时出现一些异常
我在winrt中访问文件时遇到一些问题
问题1: var file = await StorageFile.GetFileFromPathAsync(filePath); 有时,GetFileFromPathAsync将抛出“rpc服务器不可用”异常. 问题2: MusicProperties musicProp = await file.Properties.GetMusicPropertiesAsync(); 有时它会引发异常: Unable to cast COM object of type 'Windows.Storage.FileProperties.MusicProperties' to interface type 'Windows.Storage.FileProperties.IMusicProperties'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{BC8AAB62-66EC-419A-BC5D-CA65A4CB46DA}' failed due to the following error: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)). 问题3: QueryOptions query = new QueryOptions(CommonFileQuery.OrderByMusicInfo,extensionList); StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(query); IReadOnlyList<IStorageFile> files = await queryResult.GetFilesAsync(); 有时会抛出异常: Unable to cast COM object of type 'Windows.Storage.StorageFile' to interface type 'Windows.Storage.IStorageFile'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C7034384-F12E-457A-89DA-69A5F8186D1C}' failed due to the following error: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)). 这些异常不会一直抛出,但有时会抛出.为什么? 解决方法
这是由线程引起的那种问题,它是一个COM错误消息.并非完全出乎意料,WinRT基于COM.错误消息说的是在一个线程上创建的接口指针正在另一个线程上使用而没有被编组.
这是您在编写原始COM代码时通常必须自己做的事情.底层的COM辅助函数是快乐命名的CoMarshalInterThreadInterfaceInStream().但是,您显然正在使用托管代码. CLR的工作是在必要时编组指针.它已经可靠而一致地一直回到.NET 1.0版本,我从来没有见过它丢失的情况. 这非常强烈地暗示了C#await / async管道或CLR的WinRT投影中的错误.特别是因为它是虚假的,这种编组错误应该是一致的.没有什么可以自己解决的.使用connect.microsoft.com门户报告错误,他们需要一个小的repro项目来演示问题. 您现在唯一可用的解决方法是小心控制应用中的线程.通过仅使用您创建它的同一个线程上的对象来避免这种不幸.这并不能完全保证您能够逃避错误.否则,当您尝试使用pre-beta代码时,您可能会遇到什么样的问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 在远程Windows服务器上设置Git存储库?
- 什么是在Windows上运行的最佳维基?
- Windows – 允许DHCP客户端在域服务器关闭时使用公共DNS服务
- 为什么在Windows 7(x64)上安装用于Python v3.4的matplotlib
- windows – 如何在用户创建挂载点时收到通知?
- IIS中死循环的解决方法(Dllhost.exe占用CPU100%解决办法)
- windows-server-2008 – 如何在发布之前保护.NET(MVC)网站?
- .net – Windows Server 2008上的最大tcp / ip连接
- 如何在Windows上用Java读/写串口?
- windows-installer – 如何在Installshield 2018中添加发布