我正在使用Xamarin和C#。当我销毁一个活动时,我发现异步void仍在运行。
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.TableItemsMain);
RefreshTableAsync();
}
async Task RefreshTableAsync()
{
using (var client = new HttpClient())
{
client.Timeout = TimeSpan.FromMilliseconds(10000);
var response = await client.PostAsync("http://" + MyIp + ":9090/", new StringContent("2:" + MyTableName + "", Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
}
}
}
如何在销毁时处置异步空隙?