Win32Lib doEvents()
- Posted by Larry Miller <larrymiller at sasktel.net> Jul 08, 2005
- 578 views
I have found doEvents to be very useful but there is a potential problem in it's use. The problem occurs when PeekMessage in doEvents receives a WM_QUIT message. GetMessage in the event loop tests for this and terminates the loop and the application. But in doEvents there is no such test and this will cause a serious problem. The following code illustrates the problem. Yes, it is contrived and not the way an application would normally do things, but it does illustrate the basic problem.
include win32lib.ew without warning atom Win procedure handler(integer id,atom event,sequence param) if event=w32HActivate then while 1 do doEvents(0) end while end if end procedure Win=create(Window,"Test",0,100,100,600,400,0) setHandler(Win,w32HActivate,routine_id("handler")) WinMain(Win,Normal)
If you click on the windows close button the window will close, but Task Manager shows that the process is still very much alive - and with very high CPU usage. The problem does not appear to be unique to Win32Lib. I have examined the code of ARWEN and it's doEvents() function appears to work in a similar maner, and subject to the same problem. (I have not actually confirmed the problem in ARWEN). In my case I have replaced doEvents() with a procedure that does test for WM_QUIT and then shuts down the application. But I am not certain that this is the best solution to the problem. In any case this issue should be resolved in Win32Lib. Larry Miller