I´m trying to convert a "classic" asynchronous method that uses a callback into a async/await method.
This is the code:
authClient.LoginCompleted += authClient_LoginCompleted;
authClient.LoginAsync(new List<string>() { "var1", "var2" }, data);
static void authClient_LoginCompleted(object sender, LoginCompletedEventArgs e)
{ ... }
Where "data
" is a UserState
, and authClient_LoginCompleted
is the callback.
I already have the logic for a async/await methods, the problem is that the interaction in windows phone with Microsoft.Live uses callbacks. I´m considering a solution using semaphore, in order not to change the logic I have. That could be a good option?
If you need to wrap asynchronous callbacks into Task
s, then you can use TaskCompletionSource<T>
. MSDN has the full details.
However, in your case, you can just use LoginAsync
without the UserState
parameter:
LiveLoginResult result = await authClient.LoginAsync(new[] { "var1", "var2" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With