c# - 您的应用程序已进入中断状态,但没有代码可显示,因为所有线程都在 xamarin android 中执行外部代码

标签 c# android xamarin

这是我在 xamarin android 中的一段代码,当 Vs 2017 想要执行“await Task.Delay(200);”行时,会出现标题中提到的错误,请知道的告诉我

private async void _btnanswer2_Click(object sender, EventArgs e)
    {
        if(Ans == 2)
        {
            _btnanswer2.SetBackgroundColor(Android.Graphics.Color.ParseColor("#006400"));
            mScore = mScore + 1;
            _txtscore.Text = "امتیاز: " + mScore.ToString();
        }
        else
        {
            _btnanswer2.SetBackgroundColor(Android.Graphics.Color.ParseColor("#FF0000"));
        }
        await Task.Delay(200); //Error after Execute this line
     _btnanswer2.SetBackgroundColor(Android.Graphics.Color.ParseColor("0091EA"));
        bandeira++;
        RefreshQue();
    }

最佳答案

You can refer to this link ,就像@atik sarker 所说的那样。

或者你可以添加try-catch来获取错误信息。


在你的代码中,这一行

btnaanswer2.SetBackgroundColor(Android.Graphics.Color.ParseColor("0091EA"));

它将抛出 Java.Lang.IllegalArgumentException: Unknown color

因此您需要添加#,请将其替换为btnanswer2.SetBackgroundColor(Android.Graphics.Color.ParseColor("#0091EA"));

关于c# - 您的应用程序已进入中断状态,但没有代码可显示,因为所有线程都在 xamarin android 中执行外部代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48417539/

相关文章:

android - 显示具有多个帧的动画 View 的最佳策略是什么?

xamarin - 如何使用 Xamarin 表单中的 TabbedPage 在导航栏中添加徽章计数?

xamarin - 是否需要拥有 Xamarin 帐户才能在 VS 2017 中构建 Xamarin 项目

c# - 如何将依赖注入(inject)应用于抽象工厂

c# - 用户控件中的图像未显示在窗口中

android - 使用 Android Studio 的 Udacity Sunshine 应用程序 - 错误 :(21) No resource identifier found for attribute 'actionProviderClass' in package '..'

java - res-long-hdpi 的屏幕尺寸

c# - Xamarin.forms 自定义字体异常

c# - 如何更改 asp.net Core 3 或 Net Core 5 中的默认端口

c# - listview:获取子项文本