-
Notifications
You must be signed in to change notification settings - Fork 743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] Parallelize FileOpenPicker.PickMultipleFilesAsync
#18605
Comments
FileOpenPicker.PickMultipleFilesAsync
on iOSFileOpenPicker.PickMultipleFilesAsync
FileOpenPicker.PickMultipleFilesAsync
FileOpenPicker.PickMultipleFilesAsync
@darenm Can provide more information on what you tried? Thanks! |
@jeromelaban: private async void ConvertPickerResults(PHPickerResult[] results)
{
Console.WriteLine("ConvertPickerResults...");
var providers = results
.Select(res => res.ItemProvider)
.Where(provider => provider != null && provider.RegisteredTypeIdentifiers?.Length > 0)
.ToArray();
var start = DateTime.Now;
int count = 0;
foreach (NSItemProvider provider in providers)
{
var identifier = GetIdentifier(provider.RegisteredTypeIdentifiers ?? []) ?? "public.data";
var extension = GetExtension(identifier);
//var data = await provider.LoadDataRepresentationAsync(identifier);
// File Representation instead of Data Representation, I assume Data Representation pulls data into memory.
provider.LoadFileRepresentation(identifier, (url, err) =>
{
// File Representation is only valid for the lifetime of the callback. Need to copy file to temp directory here.
var destinationUrl = NSFileManager.DefaultManager
.GetTemporaryDirectory()
.Append($"{NSProcessInfo.ProcessInfo.GloballyUniqueString}.{extension}", false);
//Console.WriteLine($"Identifier: {identifier}");
//Console.WriteLine($"Copy {url.Path} to {destinationUrl.Path}");
File.Copy(url.Path, destinationUrl.Path, true);
//&&& Hack: Need to wait until all files are copied
if (++count == 100)
{
var end = DateTime.Now;
Console.WriteLine($"Took {(end - start).TotalSeconds} seconds");
}
});
}
return;
} |
I cleaned it up a little this weekend to remove the hardcoded file count: private async Task ConvertPickerResults(PHPickerResult[] results)
{
Console.WriteLine("ConvertPickerResults...");
var providers = results
.Select(res => res.ItemProvider)
.Where(provider => provider != null && provider.RegisteredTypeIdentifiers?.Length > 0)
.ToArray();
var start = DateTime.Now;
var copyTasks = new List<Task>();
foreach (NSItemProvider provider in providers)
{
var identifier = GetIdentifier(provider.RegisteredTypeIdentifiers ?? []) ?? "public.data";
var extension = GetExtension(identifier);
var tcs = new TaskCompletionSource();
copyTasks.Add(tcs.Task);
//var data = await provider.LoadDataRepresentationAsync(identifier);
// File Representation instead of Data Representation, I assume Data Representation pulls data into memory.
provider.LoadFileRepresentation(identifier, (url, err) =>
{
// File Representation is only valid for the lifetime of the callback. Need to copy file to temp directory here.
var destinationUrl = NSFileManager.DefaultManager
.GetTemporaryDirectory()
.Append($"{NSProcessInfo.ProcessInfo.GloballyUniqueString}.{extension}", false);
File.Copy(url.Path, destinationUrl.Path, true);
tcs.SetResult();
});
}
await Task.WhenAll(copyTasks);
var end = DateTime.Now;
Console.WriteLine($"Took {(end - start).TotalSeconds} seconds");
return;
} |
What would you like to be added
If the user picks multiple photos on iOS, the processing currently creates a local copy for each of them in sequence. This is inefficient.
Why is this needed
Parallelize to speed up the processing
For which platform
iOS
Anything else we need to know?
No response
The text was updated successfully, but these errors were encountered: