2

我正在表演

appts.SearchAsync 

var appts = new Appointments();

在“定期代理”中。问题在于期刊代理。searchasync 和它的嵌套函数从未完成过

NotifyComplete();
        }

您能否帮助我了解如何等待此处正在进行的所有呼叫:

static void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
        {
            try
            {
                UpdatePrimaryTile(e.Results
                .Where(a => a.Subject != null)
                .OrderBy(a => a.StartTime)
                .ToList());
            }
            catch (System.Exception)
            {

            }
        }

public static void UpdatePrimaryTile(List<Appointment> calendarItems)
        {
...........
..........
}

在调用“NotifyComplete”之前。

谢谢!

雅库布

4

1 回答 1

1

您可以使用await关键字来等待异步操作完成。

await appts.SearchAsync

另一种选择 - 有一个循环,直到异步调用完成。

appts.SearchAsync
while (true)
{
   if (searchCompleted)
   {
      break;
   }
   else
   {
      Thread.Sleep(100);
   }
}

然后在事件处理程序中......

void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
{
   searchCompleted = true;
   // Other logic
}
于 2013-05-30T13:24:12.873 回答