Can B+ Programs run after you tab out?

BlitzPlus Forums/BlitzPlus Programming/Can B+ Programs run after you tab out?

Gabriel(Posted 2003) [#1]
Tabbing out of an application seems to halt execution until I tab back. Is it possible to avoid this, so that a program can run in the background?


Beaker(Posted 2003) [#2]
Try:
Autosuspend False


Gabriel(Posted 2003) [#3]
Ooooh, thanks :)

I wondered what that was for. I saw it in one of Rob's sample programs, and I tapped F1 twice to see what it did, but it wasn't found in the help, so I forgot about it for the timebeing.


Gabriel(Posted 2003) [#4]
Hmm, nope. Makes no difference. I was running in a window, so I guess it was already set to false. Still my little server app does nothing unless it has focus.


soja(Posted 2003) [#5]
It must be the way you have it set up. Consider this program. It works find even without the focus.

CreateTimer(1)
w = CreateWindow("Test Window", 10, 10, 200, 150)
t = CreateLabel("", 10, 10, 100, 20, w, 1)
While WaitEvent()
	Select EventID()
		Case $803 : End
		Case $4001 : i=i+1 : SetGadgetText(t, i)
	End Select
Wend



Gabriel(Posted 2003) [#6]
My main loop looks exactly like that, albeit with a few calls to readavail() to check the incoming streams, so I guess that's not the problem.

However, I don't use any timer. That's not crucial, I assume? Just to get it to do something once a second, yes?


Gabriel(Posted 2003) [#7]
Ok, I think I see the problem now. The program is executing on it's own. That's fine.

The problem is that incoming data on a stream doesn't register as an event. So WaitEvent() is sitting there waiting for me to tab back into the application, at which point, it checks the streams which are checked elsewhere in the main loop.

So the question is : how can I get the program to keep checking the streams since they don't generate an event? Do I need to use a timer? And if I do, won't that increase the amount of CPU time the program is using?


soja(Posted 2003) [#8]
I think using a timer would be the best course of action.

It will (of course) increase the CPU time the program uses, but not much. What is has to do is very little, and 60 times a second (or whatever) isn't that much in terms of modern CPUs.

Just cut and paste the program above and try it. On my system, it doesn't even register (it stays at 00% whether the timer event is 1 Hz or 60 Hz). So whatever CPU time it will use will probably be more dependant on stuff you add (like checking streams, et al).


Binary_Moon(Posted 2003) [#9]
add a number to the waittimer command

waittimer(50) will update every 50 millisecs wether there is an event or not.


Gabriel(Posted 2003) [#10]
Yep, thanks guys. I've tried it with a timer, and I can have both server and client running, and it never goes about 5% cpu usage. Mostly it's 1%. That's perfect.


Binary_Moon(Posted 2003) [#11]
DOH! I didn't mean waitTimer. I meant waitevent()

use

waitevent(50)


The waitevent command has a time out option which makes it update even if there are no events.


Gabriel(Posted 2003) [#12]
Oh cool, I hadn't noticed that WaitEvent could take a value. Thanks Ben.