Re: Task scheduler sluggish

new topic     » goto parent     » topic index » view thread      » older message » newer message
penpal0andrew said...

Here is a test case to show what I am doing:

without warning 
include win32lib.ew 
 
integer win, button1 
integer color 
atom taskthetask 
 
procedure thetask() 
while w32True do 
	setWindowBackColor( win, color ) 
	color = color + 20 
	task_yield() 
end while 
end procedure 
taskthetask = task_create(routine_id("thetask"),{}) 
 
procedure click1(integer self, integer event, sequence parms) 
	task_schedule(taskthetask,{0.1,0.3}) -- do every 200 ms 
end procedure 
 
procedure main() 
 
	color = 0 
 
    win = createEx(Window, "Test task schedule", 0, 0, 0, 400, 200, 0, 0) 
    button1 = createEx(Button, "start task", win, 0, 80, 90, 20, 0, 0) 
  
    setHandler(button1, w32HClick, routine_id("click1")) 
    WinMain(win, Normal) 
 
end procedure 
 
main() 

The problem is that it is very sluggish to run the task. But if I move the mouse around inside the window, the task works at its proper speed.

So, how do I get a task to run every 200 ms, whether or not someone is doing something else at the same time. And yes, I still want other stuff to go on if the user chooses.

Andy K.

My experience with Euphoria tasks is limited so I won't suggest how best to use them. But I do see why you are having this problem. A typical Windows application spends most of it's time waiting for messages. While a thread is waiting for a message it can do nothing else. A Euphoria process has but one thread. Yes, Euphoria has tasks but they are implemented within the interpreter and the system knows nothing of them.

While the single euphoria thread is waiting for a message it can do nothing else, and that means that Euphoria's task sheduler isn't even running. There is no way it can call your thread. When you move the mouse or press a key it becomes active again and the scheduler is able to run again.

I don't think that Euphoria threads are a good fit here. If or when Euphoria has real threads this will be possible. Until then you will need to find another way. One way would be to use a timer that sends a message every 200ms.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu