/// <summary> /// Asynchronously searches for contacts in the user’s contact data. /// </summary> /// <param name="contacts">The contacts which will be searched.</param> /// <param name="filter">The filter to use to search for contacts.</param> /// <param name="filterKind">The kind of filter to use when searching for contacts.</param> /// <param name="state">A user-defined object that contains information about the operation.</param> /// <returns>The task object representing the asynchronous operation. The Result property /// on the task object returns search results.</returns> public static Task<ContactsSearchEventArgs> SearchTaskAsync(this Contacts contacts, string filter, FilterKind filterKind, object state) { if (contacts == null) throw new NullReferenceException(); var tcs = new TaskCompletionSource<ContactsSearchEventArgs>(); EventHandler<ContactsSearchEventArgs> handler = null; handler = (sender, e) => { contacts.SearchCompleted -= handler; tcs.TrySetResult(e); }; contacts.SearchCompleted += handler; try { contacts.SearchAsync(filter, filterKind, state); } catch { contacts.SearchCompleted -= handler; throw; } return tcs.Task; }
public ContactSearchArguments(string filter, SearchKind searchKind, FilterKind filterKind, object state) { this.Filter = filter; this.FilterKind = filterKind; this.SearchKind = searchKind; this.State = state; }
/// <summary> /// Gets a list of contacts in device address book filtered by search criteria /// </summary> /// <param name="searchTerm">Search term</param> /// <param name="callback">Callback</param> /// <param name="filter">Filter</param> /// <returns>List of contact</returns> private void SearchContacts(Action<List<Contact>> callback, FilterKind filter = FilterKind.None, string searchTerm = null) { var cons = new Contacts(); cons.SearchCompleted += (s, e) => callback(e.Results.ToList()); cons.SearchAsync(String.IsNullOrEmpty(searchTerm) ? string.Empty : searchTerm, filter, null); }
/// <summary> /// Gets a list of contacts in device address book filtered by search criteria /// </summary> /// <param name="searchTerm">Search term</param> /// <param name="filter">Filter</param> /// <returns>List of contact</returns> public Task<List<Contact>> Search(string searchTerm, FilterKind filter) { var t = new TaskCompletionSource<List<Contact>>(); SearchContacts(s => t.TrySetResult(s),filter,searchTerm); return t.Task; }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { InputScope scope = new InputScope(); InputScopeName scopeName = new InputScopeName(); contactFilterKind = FilterKind.DisplayName; scopeName.NameValue = InputScopeNameValue.Text; scope.Names.Add(scopeName); contactFilterString.InputScope = scope; //contactFilterString.Focus(); DoSearch(); ContactResultsData.Focus(); CheckInTimer.Interval = new TimeSpan(0, 0, 5); CheckInTimer.Tick += TimerTick; }