Question <- (Yet another) -- How do I run multiple functions at once in Console?

Mynotoar

Active member
Joined
Sep 27, 2012
Messages
28
Location
England
Programming Experience
Beginner
Hey guys... sorry to keep bugging you, but you really are wonderfully helpful when it comes to VB, and I could much use your input again!

Our Computing teacher is encouraging us to try making games with Console in VB, and I like the idea, but there's one big problem with a lot of games that I don't know how I'd get around: there needs to be a game tick that's running constantly, but while the tick is running you would be able to use inputs as well. For example, say Tetris. The blocks are falling constantly, every tick they move down, but while the time is elapsing from one game-tick to the next, the Console needs to allow you to be able to read a ConsoleKey so you can change the path of that block or rotate it.

I've heard something about Threading which runs multiple functions at once - is this the sort of thing I need to be looking into? At the moment, all I know how to use is Threading.Thread.Sleep(Val in Milliseconds) to hold the Console (thanks Ian!), but is there any way to use this principle to accept input while the Console is waiting? Is there an even simpler way I'm overlooking?

If it is Threading or something even more complicated, I'd very much appreciate if someone could intuitively explain to me how it would work - I've only been doing VB for four months and a lot of the more complicated stuff I find very hard to grasp.

Hope you can help! Thanks a lot in advance!
 
Hi Leo,

If you feel that Threading is the way to go with what you are looking to do then I would suggest that you take a look at the BackgroundWorker class first. This class allows you to complete tasks on a separate thread and allows you to report results as you need to the current UI thread. This is a good place to start if you are looking at threading for the first time.

BackgroundWorker Class (System.ComponentModel)

However, with regards to your comments about a Tetris game I am not sure whether threading would be the way to go. If you think about a single block for a moment, you would use a timer to allow the block to drop down your game screen in a controlled manner. At the same time you would code the Keydown event of the form to check for the keys defined for rotation or movement and control the block on the same UI thread as the timer which seems to make sense to me.

Hope that helps.

Cheers,

Ian
 
Back
Top