私はXamarin FormsとMVC API .netを使用してWeb APIサービスを実装しています。 Authサービスを作成しました。私はPostmanアプリを使用してアクセストークンを取得できます。 UWPプラットフォームでプロジェクトを実行すると、アプリは正常に動作し、Web APIにアクセスするためのトークンを取得できます。しかし、私はAndroidプラットフォーム上でアプリケーションを実行するたびに、私は "36フレームはスキップされているという処理されない例外が発生します。アプリケーションはメインスレッドであまりにも多くの作業をしている可能性があります"。私は非同期を使用しています...メソッドを待って、このエラーが発生します。どうすればこのエラーを回避できますか?ありがとうございました!Xamarinフォーム - Androidスレッド
ApiServices:ここ
は私のコードですpublic class ApiServices {
public async Task RegisterUserAsync(string email, string password, string confirmPassword) {
var client = new HttpClient();
var success = false;
var model = new RegisterBindingModel {
Email = email, Password = password, ConfirmPassword = confirmPassword
};
try {
var json = JsonConvert.SerializeObject(model);
HttpContent content = new StringContent(json);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
if (email != null || password != null) {
success = true;
Acr.UserDialogs.UserDialogs.Instance.ShowSuccess(string.Format("You are now signed-in as {0}.", email));
var response = await client.PostAsync(Constants.BaseApiAddress + "api/Account/Register", content);
Debug.WriteLine(response);
Debug.WriteLine(await response.Content.ReadAsStringAsync());
Debug.WriteLine(response.StatusCode);
}
} catch (Exception ex) {
//Acr.UserDialogs.UserDialogs.Instance.ShowError(string.Format("Authentication Failed: {0}", ex.Message));
}
}
}
LoginViewModel:
public class LoginViewModel {
public string Email {
get;
set;
}
public string Password {
get;
set;
}
public ICommand LoginCommand {
get {
return new Command(async() => {
ApiServices apiServices = new ApiServices();
await apiServices.LoginUserAsync(Email, Password);
});
}
}
}
プッシュすべてそのコード '待つTask.Run(...);' – SushiHangover