0

「DeleteAsync」がファイルを削除しないのに、「File.Delete」が削除するのはなぜだろうか。誰かが私にこれを説明できますか?最初はファイルが開いていると思いますが、ファイルが開いている場合は「File.Delete」でも削除してはいけませんか...?

private static async void FILESYSTEM_RemoveVideoPosterIfExist(string posterFileNameOnStorage)
{
    IStorageItem videoPosterIStorageItem = await ApplicationData.Current.LocalFolder.TryGetItemAsync(SYSTEM_UserVideoPosterFolder + @"\" + DATABASE_SelectedUserInformation.UserName + "." + SYSTEM_UserPosterFolderExtension + @"\" + posterFileNameOnStorage);
    if (videoPosterIStorageItem != null)
    {
        try
        {
            //Why this doesn't delete file...
            await videoPosterIStorageItem.DeleteAsync(StorageDeleteOption.PermanentDelete);
        }
        catch
        {
            //But this one will delete file.
            StorageFolder applicationStorageFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync(SYSTEM_UserVideoPosterFolder + @"\" + DATABASE_SelectedUserInformation.UserName + "." + SYSTEM_UserPosterFolderExtension + @"\");
            File.Delete(applicationStorageFolder.Path + @"\" + posterFileNameOnStorage);
        }
    }
}
4

1 に答える 1

2

その理由は、ファイルを非同期で削除するためのネイティブ関数がないためである可能性があります。マネージ API は通常、アンマネージ API のラッパーです。

これを見てください

.net に非同期ファイル削除がないのはなぜですか?

 FileInfo fi = new FileInfo(fileName);
 await fi.DeleteAsync(); // C# 5
 fi.DeleteAsync().Wait(); // C# 4

お役に立てれば!!

于 2016-12-03T11:44:24.807 に答える