error CS0103

ansalc 436 Reputation points
2020-04-20T20:20:37.977+00:00

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.

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. ansalc 436 Reputation points
    2020-04-21T10:16:31.077+00:00

    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 additional answer

Sort by: Most helpful
  1. Techmax 1 Reputation point
    2022-08-26T06:50:45.243+00:00

    CS0103 is caused when you are using a name for a variable or method that does not exist within the context that you are using it. In order to fix the CS0103 error you will need to correct the name of the variable or method from where it is declared or referenced.

    Regards,
    Techmaxguy

    0 comments No comments