2

this is a piece of my code in xamarin android , When Vs 2017 want to execute the line "await Task.Delay(200);" , the error mentioned in title will apear, please tell me if anybody know about that

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();
    }
omid-ahmadpour
  • 63
  • 1
  • 12

1 Answers1

1

You can refer to this link, do like @atik sarker has said.

Or you can add try-catch to get the error message.


In your code, this line

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

It will throw Java.Lang.IllegalArgumentException: Unknown color

So you need add #, please replace it with btnanswer2.SetBackgroundColor(Android.Graphics.Color.ParseColor("#0091EA"));

Robbit
  • 4,300
  • 1
  • 13
  • 29