locked
FindContactsAsync takes long time RRS feed

  • Question

  • I am developing a Windows Phone 8.1 Silverlight application, in which I find that the method FindContactsAsync in  Windows.ApplicationModel.Contacts class takes about 15 seconds to return data for my device with 127 contacts.

    A similar method in WP8 SDK, SearchAsync in Microsoft.Phone.UserData.Contacts completes within 2 seconds.

    To compare I have this code:

      public async Task<List<PhoneContact>> FindContactsAsync()
            {
                var contactStore = await Windows.ApplicationModel.Contacts.ContactManager.RequestStoreAsync();
    
                var contacts = await contactStore.FindContactsAsync();
    
                return contacts.SelectMany(c => c.Phones
                     .Select(p => new PhoneContact { DisplayName = c.DisplayName, Number = p.Number, Thumbnail = ShowPictures ? c.Thumbnail : null })).ToList();
            }
    
     public Task<List<PhoneContact>> FindContactsAsync()
            {
                var tsk = new TaskCompletionSource<List<PhoneContact>>();
                var contactStore = new Microsoft.Phone.UserData.Contacts();
             
                contactStore.SearchCompleted += (sender, e) =>
                {
                    try
                    {
                        var contacts = e.Results.SelectMany(c => c.PhoneNumbers.Select(p => new PhoneContact
                        {
                            DisplayName = c.DisplayName,
                            Number = p.PhoneNumber,
                            //Thumbnail = ShowPictures?() => c.GetPicture():null
                        })).ToList();
                        tsk.SetResult(contacts);
                    }
                    catch
                    {
                        tsk.SetResult(new List<PhoneContact>());
                    }
    
                };
                contactStore.SearchAsync("", Microsoft.Phone.UserData.FilterKind.None, null);
                return tsk.Task;
            }
    I suppose the WP8.1 sdk method is a new one but takes lot of time. Going forward, which method is best suited for development and efficiency.


    -Shubhan

    Tuesday, April 29, 2014 2:00 PM

Answers

All replies