private async void loop() { ConcurrentBag <String> people = new ConcurrentBag <string>(); while (this._loopInProgress) { if (_lastFaces != _cameraControl.LastFaces && _cameraControl.LastFaces != null) { _lastFaces = _cameraControl.LastFaces; await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { if (_personGroups != null) { foreach (var group in _personGroups) { foreach (var face in _cameraControl.LastFaces) { IdentifyResult[] results; try { results = await FaceService.IdentifyAsync(group.PersonGroupId, _cameraControl.LastFaces); foreach (var result in results) { if (result.Candidates.Length > 0) { var resultCandidate = result.Candidates[0]; //Let's start with 50% confidence for now if (resultCandidate.Confidence > 0.5) { try { var identifiedPerson = await FaceService.GetPersonAsync(group.PersonGroupId, resultCandidate.PersonId); people.Add(identifiedPerson.Name); } catch { //return; } finally { APICalls++; } //Currently we take the first best person //Message = String.Format(loader.GetString("Main_Message_Back"), identifiedPerson.Name); //return; } } } } finally { APICalls++; } if (!people.IsEmpty) { string peopleNames = ""; foreach (var item in people) { peopleNames = peopleNames + ", " + item; } Message = String.Format(loader.GetString("Main_Message_Back"), peopleNames); } } } } }); } if (people.IsEmpty) { //Wait 1 seconds to save API calls await Task.Delay(1000); } else { while (!people.IsEmpty) { string name; people.TryTake(out name); } //We found some people we know. Wait 5 seconds to save API calls await Task.Delay(5000); } } }