文件我有一些問題,當我在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)).
這些例外不會一直拋出,但有時會拋出。爲什麼?