C
C#16mo ago
Eagle

✅ After 2 wrong guesses, the program closes immediately

As the title says, after 2 wrong guesses the program doesnt show the text, or wait 3000 milliseconds. It just closes immediately. I dont know if Environment.Exit is a correct command to use in this situation, i just looked it up. Basically, after 2 wrong guesses i want the program to wait 3 seconds and then close.
8 Replies
Kouhai
Kouhai16mo ago
You're not awaiting Task.Delay
mindhardt
mindhardt16mo ago
If you are a beginner you may use Thread.Sleep instead of Task.Delay. tho in actual apps it is a no-go, but I suggest to not weigh yourself with async/await for now
Eagle
Eagle16mo ago
okay, thank you. so there isnt any beginner-friendly way for the program to wait?
mindhardt
mindhardt16mo ago
Thread.Sleep is simple but it blocks the thread, which will concern you only after you start creating multi-thread programs
Eagle
Eagle16mo ago
Okay, thanks, ill try to use thread.sleep and see how it goes ill be sure to change that after learning about these multi thread programs
mindhardt
mindhardt16mo ago
You may as well do
Task.Delay(3000).RunSyncronously();
Task.Delay(3000).RunSyncronously();
Afair it will work the same way
Eagle
Eagle16mo ago
this gives me some errors, ill use the thread.sleep for now
mindhardt
mindhardt16mo ago
Consider /closeing this thread