hej, nie uzywalem nigdy ConcurrentDictionary, próbuje pobrac ze Storage pliki, jednak jest ich całkiem sporo, więc chciałem pobierać jednocześnie wiele
ustukałem taki kod
public static async Task<ConcurrentDictionary<string, Stream>> GetBlobsParallel(
BlobContainerClient container,
IEnumerable<string> filesPaths,
int division=500)
{
var distinctFilesPath = filesPaths.Distinct();
var result = new ConcurrentDictionary<string, Stream>();
var divided = Divide(distinctFilesPath, division);
Parallel.ForEach(divided, async (files) =>
{
foreach (var file in files)
{
try
{
var blob = await (GetBlob(container, file));
result.TryAdd(file, blob);
}
catch
{
result.TryAdd(file, FileNotFoundStream());
}
}
});
return result;
}
static MemoryStream FileNotFoundStream() => new MemoryStream(Encoding.UTF8.GetBytes("FILE NOT FOUNND"));
Jednak problem jest w tym, że od razu przechodzi do return result, no chyba że sobie wolno debuguje, to pare razy trafi do try, ale i tak result jest zawsze pusty (0 elementów)
Co tu jest nie tak ?
sama metoda Getblob działa jak coś ;)
a metoda Divide działa na mniejsze IEnumerable
static IEnumerable<IEnumerable<T>> Divide<T>(IEnumerable<T> data, int division)
{
var result = new List<IEnumerable<T>>();
int skip = 0;
IEnumerable<T> divedData = data.Skip(skip).Take(division);
while (divedData.Any())
{
result.Add(divedData);
skip += division;
divedData = data.Skip(skip).Take(division);
}
return result;
}
btw program nadal "działa" ale zawiesza sie całe visual :D