question

ansalc-1556 avatar image
0 Votes"
ansalc-1556 asked ·

error CS0103

When I run my code (that compiles ok) I get at line:

Button3.Content = "Hello"

the following error:

"content error CS0103: The name 'content' does not exist in the current context"

The same code executes as expected in a project that has the same structure.

How can I avoid this error and set the content of the button?

Thanks.

windows-uwp
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, please check whether there is a syntax error. Is Button3 the name of the button control? Could you please show the complete code or provide a minimum runnable demo?

0 Votes 0 ·

1 Answer

ansalc-1556 avatar image
0 Votes"
ansalc-1556 answered ·

I have been able to avoid the error by using Await Task.Delay. My code is now:

             StartTime = DateTime.Now

             Button3.IsEnabled = False

             Button3.Content = StartTime.TimeOfDay.ToString.Split(".")(0)

             Await Task.Delay(60000).ConfigureAwait(True) 

Before, the last line was:

            Task.Delay(60000).Wait()

It seems that with Task.Delay the previous content is not captured and execution fails (same happens if I use Await Task.Delay(60000).ConfigureAwait(False))

I do need the long delay because I have to wait for an external device to boot up

What I do not yet understand is why I get no error in the other program that has the same code and uses Task.Delay.

Anyway. I will use Await Task.Delay from now on, which seems to have the additional benefit of allowing me to interact with the UI while the task is delayed.

I need to study and understand better the differences and implications of using the two alternatives to insert a delay in the execution of code.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Glad you found a solution, you can accept it as the answer, this will help more people who have the same problem as you

0 Votes 0 ·