在我们的Xamarin Forms App中,我们必须从多个API加载大量数据.最简单的方法是直接从PCL使用HttpClient,但是当有数百个它时我得到了这个错误.
有了这个页面,我可以在一个新的PCL项目中重现这个问题.
using System;
using Xamarin.Forms;
namespace HTTPTest
{
public class HTTPTestPage : ContentPage
{
int Index = 0;
public HTTPTestPage()
{
Content = new Label
{
Text = "HTTP Test"
};
}
protected override void OnAppearing()
{
base.OnAppearing();
StartLoading();
}
void StartLoading()
{
for (int i = 0; i < 400; i++)
{
if (string.IsNullOrEmpty(LoadStringFromEndpoint("https://google.de")))
{
break;
}
}
}
public string LoadStringFromEndpoint(string url)
{
System.Diagnostics.Debug.WriteLine("LoadFromEndpoint: " + url);
try
{
Index++;
var client = new System.Net.Http.HttpClient(); …Run Code Online (Sandbox Code Playgroud)