B+: Simple time-reminder without 100% CPU usage?

Blitz3D Forums/Blitz3D Beginners Area/B+: Simple time-reminder without 100% CPU usage?

I don't get why it's "Not Responding", in a simple Repeat-Forever loop..?

The answer is *because* you're in a repeat-forever loop. You see, the program is busy working between the Repeat and Forever, and you are not allowing it to even pay attention to events that Windows sends to it (like move, focus, resize, close, etc) -- so to Windows, it is unresponsive. This is what I meant up above where I said "your program does not have to halt execution"... I guess I said that wrong. Your program is still executing (of course) but Windows doesn't know about this.

What you have to do to fix this is make sure that WaitEvent is called in your loop. Whenever WaitEvent is called, Blitz (behind the scenes) starts looking for Windows event messages that Windows sends to it. You don't see this happen, but it does, and it's what keeps it responsive in Windows. It's also how you get the event messages.

I recommend an Event Loop like this:

CreateTimer(1) ; Timer that fires an event $4001 once per second
Target% = 5 ; 5 seconds -- change this to your textfield number
bCounting% = False ; has the user clicked the Go button?
tick% = 0 ; how long has it been since the user clicked Go?

While WaitEvent()
	Select EventID()
		Case $803 : End
		Case $401 : If EventSource() = BtnButton Then bCounting = True
		Case $4001 ; Timer event (once per second)
			If bCounting Then
				tick = tick + 1
				If tick = Target Then 
					bCounting = False
					tick = 0
					Notify "Target reached!"
				EndIf
			EndIf
	End Select
Wend