質問

i am trying to sync the contacts to server after every 24 hours . so for that purpose I am using background agent. when I try to call contacts it does not get the contacts of the phone . my code is here ...

protected override void OnInvoke(ScheduledTask task)
{        
   Contacts cons = new Contacts();

   //Identify the method that runs after the asynchronous search completes.
   cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);

   //Start the asynchronous search.
   cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");

  #if DEBUG_AGENT
   ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(10));
  #endif    
}

void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
  var a = e.Results;

  //  e.Results.Count();
  NotifyComplete();
}

can anybody let me know what is the issue or suggest a better way ....

役に立ちましたか?

解決

Use this code to get the result from the SearchAsync function:

List<Contact> contacts = new List<Contact>( e.Results );
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top