2

When I was in an API call Microsoft interface need to pop up Microsoft's login screen, found that only "await the Dispatcher. RunAsync (CoreDispatcherPriority. Normal, async () = >" approach run will pop up, but here can't wait to return results will execute the following code, If it's not "await the Dispatcher. RunAsync (CoreDispatcherPriority. Normal, async () = >", Microsoft's login screen can't pop up, direct return 401, excuse me, how can pop up the login interface, and can return a result, such as this is my code:

await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
    //WriteXML(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
    back = await GetData(messageContent, "service");

    //Task.Run(async () => { back = await IC.GetData(messageContent, "service"); }).Wait();
});

I need to "ask GetData(messageContent, "service");" Return the data before executing the following code

Presto
  • 888
  • 12
  • 30
Values
  • 227
  • 2
  • 10
  • 3
    Possible duplicate of [RunAsync - How do I await the completion of work on the UI thread?](https://stackoverflow.com/questions/19133660/runasync-how-do-i-await-the-completion-of-work-on-the-ui-thread) – MT-FreeHK Jul 03 '18 at 04:58
  • Thank you very much for your reply – Values Jul 03 '18 at 07:03
  • hi @Values, Does the above comment answer your question? – Nico Zhu Jul 03 '18 at 07:07
  • @Nico Zhu Yes, but I need to transfer parameters to "ShowMessageAsync", I don't know how to achieve it. – Values Jul 03 '18 at 07:11
  • Could you show more info about parameters where you have used? – Nico Zhu Jul 03 '18 at 07:40
  • If you have used await key word ahead of `GetData` method. the following code will not be executed until `GetData` method finished. – Nico Zhu Jul 03 '18 at 08:29
  • But running in "Dispatcher.RunAsync", await does not work. – Values Jul 03 '18 at 08:33
  • @Nico Zhu - MSFT – Values Jul 03 '18 at 08:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/174226/discussion-between-nico-zhu-msft-and-values). – Nico Zhu Jul 03 '18 at 09:01
  • You'd better split asynchronous submission out of `GetData` method, because when your pop page displayed, the submission invoke Immediately, but you have input nothing, so, you could submit user info in pop page `ok` button click method. – Nico Zhu Jul 04 '18 at 07:14

0 Answers0