小编jin*_*o78的帖子

ObjectDisposedException:CancellationTokenSource已被释放

我开始使用Xamarin.Forms在我的MacBook Pro上使用Xamarin Studio进行开发.我构建了一个应用程序,其目的是查询PrestaShop网站,检索产品并显示它们.

在将应用程序部署到Android时,我在Marshmallow下面的版本遇到了一些问题,但是我解决了它们,所以我不会在这里描述它们.

在将应用程序部署到iOS(模拟器)时,我仍然遇到了严重的问题.该应用程序运行,但是当我点击按钮来检索数据,它崩溃给我System.ObjectDisposedException,是"CancellationTokenSource已被释放",其消息.我将在此粘贴相关的源代码:

async void button1_Click(object sender, System.EventArgs e)
{
    try
    {
        HttpClientHandler hnd = new HttpClientHandler();
        hnd.Credentials = new NetworkCredential("[apikey]", "");
        string res;
        using (var client = new HttpClient(hnd))
        {
            var responseText = await client.GetStringAsync("[endpoint]/products");
            using (MemoryStream stream = new MemoryStream())
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(responseText.Replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", string.Empty));
                writer.Flush();
                stream.Position = 0;
                XDocument doc = XDocument.Load(stream);
                res = JsonConvert.SerializeXNode(doc, Formatting.Indented, true);
            }
            var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(res);
            //Result.Text = data["products"].GetType().ToString() + Result.Text;
            Func<string, …
Run Code Online (Sandbox Code Playgroud)

c# xamarin.ios ios xamarin.forms

4
推荐指数
1
解决办法
6299
查看次数

标签 统计

c# ×1

ios ×1

xamarin.forms ×1

xamarin.ios ×1