UPDATE:
public MobileServiceUser CurrentMsUser { get; private set; }
I have an instance property CurrentMsUser
which is populated and I'm trying to reference it within an async method, but for some reason it is null in the method. I've set a breakpoint on the property setter and it never is set to null, so I'm fairly certain the property never becomes null. After the async method returns it's present again. It seems as soon as I'm within the anonymous async method I can't access the property. Here is my method:
public async Task CreateOrRetrieveAppUserAsync()
{
await Task.Run (async () => {
try {
var usersCollection = await _userTable.ToCollectionAsync ();
var users = usersCollection.
Where(x =>
x.FacebookToken == CurrentMsUser.UserId).
ToList();
if (users.Count == 1) {
CurrentRwUser = users [0];
} else {
CurrentRwUser = new User {
FacebookToken = CurrentMsUser.UserId,
GoogleToken = "test",
TwitterToken = "test",
MicrosoftToken = "test",
Email = "test@gmail.com",
FacebookId = App.FacebookProvider.GetCurrentUserId (),
Name = App.FacebookProvider.GetCurrentUserName ()
};
await InsertUserAsync (CurrentRwUser);
await SyncAsync();
}
} catch (Exception ex) {
Debug.WriteLine ("CreateOrRetrieveAppUser failed: {0}", ex.Message);
}
}).ConfigureAwait(continueOnCapturedContext:false);
}