폴더에 여러 파일 (> 300..1000)이 포함되어 있고 디스크 드라이브가 매우 빠르지 않은 경우 전체 파일 목록을 안정적으로로드하는 코드를 가져올 수 없습니다. 먼저 Moon 위치에 따라 10 또는 100과 같은 몇 개의 파일을로드합니다. 다음 시도 (동일한 코드를 실행)는 예를 들어 200과 같이 약간 더 반환되지만이 수가 증가 할 것이라는 보장은 없습니다. 포함UWP - 안정적으로 파일을 폴더에서 가져 오는 방법은 무엇입니까?
내가 노력 많은 변종 :
res = new List<StorageFile>(await query.GetFilesAsync());
과 :
public async static Task<List<StorageFile>> GetFilesInChunks(
this StorageFileQueryResult query)
{
List<StorageFile> res = new List<StorageFile>();
List<StorageFile> chunk = null;
uint chunkSize = 200;
bool isLastChance = false;
try
{
for (uint startIndex = 0; startIndex < 1000000;)
{
var files = await query.GetFilesAsync(startIndex, chunkSize);
chunk = new List<StorageFile>(files);
res.AddRange(chunk);
if (chunk.Count == 0)
{
if (isLastChance)
break;
else
{
/// pretty awkward attempt to rebuild the query, but this doesn't help too much :)
await query.GetFilesAsync(0, 1);
isLastChance = true;
}
}
else
isLastChance = false;
startIndex += (uint)chunk.Count;
}
}
catch
{
}
return res;
}
이 코드는 비트 복잡한 보이는,하지만 난 이미 단순한 변종을 :(시도했다
겠습니까 이걸 도와 줘서 기뻐.