我在一个解决方案中有两个项目。核心和机器人。在Droid项目中,我有一个方法需要在异步方法IN CORE完成其任务时调用。 我在Core中的代码是:
<form action="{{route('quiz.storeQuestions')}}" method="POST">
{{csrf_field()}}
@for($i = 0; $i < $questions;$i++)
<input type="text" name="question[]" value="">
<br>
@for($j = 0;$j < 4;$j++)
Choose <input type="checkbox" name="isCorrect[{{$i}}][]" value="0" onchange="check()">
<input type="text" name="choice[]">
<br>
@endfor
<br>
@endfor
<br>
<input type="submit">
</form>
我需要调用放在Droid中的方法“AuthorizationFailed”:
public async Task<bool> UsersAuthenTask(string email, string password, Action<Intent> startActivityDroid, Intent intent)
{
var httpClient = GetHttpClient(email, password);
//var response = await httpClient.GetAsync(UsersAuth.ClientsApiBaseUri + email + "password="+password).ConfigureAwait(false);
var response = await httpClient.GetAsync(UsersAuth.ClientsApiBaseUri).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
startActivityDroid(intent);
}
else
{
//I NEED TO START METHOD FROM DROID HERE
}
return false;
}
答案 0 :(得分:2)
由于您的Auth任务是异步的,所以您需要做的就是等待结果并在结果为false时调用失败的消息。您需要修改UsersAuthenTask以针对每种情况适当地返回true / false。
login.Click += async delegate
{
activityIndicator.Visibility = Android.Views.ViewStates.Visible;
var auth = new UsersAuthentication();
var result = await auth.UsersAuthenTask(email.Text,password.Text, StartActivity, new Intent(this, typeof(IndMassActivity)));
if (!result) {
AuthorizationFailed();
}
};