✅ I need help in my code
If i press a key to return to the main menu then the console get cleared first and if i press a key again then i go back to the menu but i dont want to press 2 times i only want to press a key one time to go back to the menu
35 Replies
the code is in zaal.cs
the method name is showcountdowntimer
Hey, please upload the code to github or $paste
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
We won't download a zip to help, you need to put the effort in to lower the barrier for potential helpers
GitHub
GitHub - RafCamora123/Cinema
Contribute to RafCamora123/Cinema development by creating an account on GitHub.
Does this work?
yeah thats better
I'm immediately confused as to why you have newtonsoft json in there
modern C# mostly use System.Text.Json instead
oh im working with dotnet 8.0 or 7.0
yeah. STJ has been available since .net 5
ohh okay
Yeah so the problem is if the timer runs out and is 0 then i am not be able to press a key to go back to the menu from where i chose the options first
well, the problem is likely related to your threading
because directly after starting that thread, I see this code
if you run the program you see the menu 1: show seats
2: show movies
3: show tickets
4: koffie
5: cancel reservation
6: quit
and if you press 1 you can choose chairs but if the timer runs out then i cant go back to this menu 1: show seats
2: show movies
3: show tickets
4: koffie
5: cancel reservation
6: quit
yes
so you run a loop that expects input
so the "first" keypress goes into that
and the second one goes to the readline in
ShowCountdownTimer
hmm
how can i have the loop and that isnt expecting input?
you might be able to quite easily fix this by not blocking unless there is something to read
it goes very wrong if i run the program
if its 0 and press a key like for example h
ConsoleKeyInfo keyInfo = Console.ReadKey();
can be prefixed with a if(Console.KeyAvailable)
and if i press on accident the downarrow then everything is gone
its so weird
i get now the errors oldcol, oldrow and keyinfo does not exist in the current context
yeah you need to fix your scopes
if
creates a new block of code
so you cant very well access the result of the read if the read never happenedoh
its so hard 😦
its only hard because you introduced threading
doing console input (which is blocking) in a multithreaded application is a big no-no
okay
you could have done the countdown differently, by capturing the "start" and then comparing now to start after each input
if the time ran out, say "sorry, last input was ignored as the time ran out."
bam, no threading needed
i have a lot of threading
the problem is that if you currently have a
ReadKey
or similar active when another thread "wants to do something", it canti have now removed the threading but im not be able to select chairs https://paste.pythondiscord.com/S57Q
it needs to wait for the read operation to finish
wait i forgot to remove the //thread comment
if all you did was remove the threading, thats obviously not gonna work
you cant just remove the "run in a separate thread" part and assume everything else will work
the timer runs but selecting doesnt work
you'd need to re-write the whole choice loop logic
I gotta go for a few hours, best of luck
!close
Closed!