public ShowPersonMatchedFilesControl(PersonExtended person) { _person = person; InitializeComponent(); txtTitle.Text = $"Listing matched files for {person.Person.Name}"; Loaded += ShowPersonMatchedFilesControl_Loaded; }
/// <summary> /// Gets trained faces from the API. /// </summary> /// <param name="person">The person.</param> /// <param name="guidList">The unique identifier list.</param> /// <returns></returns> private async Task GetFacesFromServerAsync(PersonExtended person, ConcurrentBag <Guid> guidList) { var tasks = new List <Task>(); Guid guid; while (guidList.TryTake(out guid)) { tasks.Add(Task.Factory.StartNew((object inParams) => { var prm = (Tuple <PersonExtended, Guid>)inParams; try { var face = faceServiceClient.GetPersonFaceInLargePersonGroupAsync(SelectedGroup.Group.LargePersonGroupId, prm.Item1.Person.PersonId, prm.Item2).Result; this.Dispatcher.Invoke( new Action <ObservableCollection <Microsoft.ProjectOxford.Face.Controls.Face>, string, PersistedFace>(UIHelper.UpdateFace), prm.Item1.Faces, face.UserData, face); } catch (FaceAPIException e) { // if operation conflict, retry. if (e.ErrorCode.Equals("ConcurrentOperationConflict")) { guidList.Add(guid); } } catch (Exception ex) { guidList.Add(guid); this.Dispatcher.Invoke(() => { MainWindow.Log($"Rate limit exceeded, Re-queuing in 1 second"); Task.Delay(1000).Wait(); }); } }, new Tuple <PersonExtended, Guid>(person, guid))); if (tasks.Count >= _maxConcurrentProcesses || guidList.IsEmpty) { await Task.WhenAll(tasks); tasks.Clear(); } } await Task.WhenAll(tasks); tasks.Clear(); return; }