How to change String value after 5 seconds?

I am ready to write a program that after 5 seconds shows the text that was hidden, and after 5 seconds I changed both. Example: - starting the program: TEXT 1 - after 5 seconds: TEXT 1 TEXT 2 - after 5 seconds: TEXT 3 - after 5 seconds: TEXT 3 TEXT 4 ...

How can I count these seconds in C #?

+3
source share
6 answers

If your view should not respond within the first 5 seconds, you put the user interface thread in sleep mode and then change it. This way you can avoid passing the functionality back to the user interface thread.

-1
source

You can use timer .

+7

.NET ( ). Windows Forms, System.Windows.Forms.Timer Tick. ( , , 5000 5 .) .

, System.Threading.Timer ( , ). ( , GUI, . Form.Invoke() Form.InvokeRequired.)

var timer = new System.Threading.Timer(
    (object state)=>{ /* Your logic here */ },
    null,
    0,
    5000);
...
timer.Dispose(); // Don't forget to Dispose of the Timer when your app closes
+5
source

For a good example, see EggTimer in C # :

This simple timer application will count down from any value set in the text box.

+2
source

There are many options. System.Threading.Sleep allows you to block a specific time. System.Threading.WaitHandle does as well, and you can interrupt sleep if you need to. Finally, you can use the timer. In all cases, make sure that you synchronize your work correctly.

+1
source

Try to use Timer.

0
source

Source: https://habr.com/ru/post/1736144/


All Articles