Click to See Complete Forum and Search --> : Multitasking in Win 3.1


Zubin Sethna
October 12th, 1999, 12:55 AM
Hi

I am writing an app for Windows 3.1 using VC++ 1.5 and I have a class which continuously polls the serial port (this class does not derive from any MFC class). While polling the serial port I want the GUI of my application to function normally. How can I make Windows service my gui while the polling goes on in the background???


Thanks for any help offered.


Zubin

eric33
October 12th, 1999, 01:23 AM
Win 3.1 is a cooperative system that means it is not a real multitasking system.

To avoid having the user interface blocks do the following :


while ( PeekMessage(&msg,NULL,0,0,PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}




But be careful because the GUI of your application cannot works (events, ...) because you code pointer is doing something else.

The better way is to handle your serial port communication asynchrounsly.
For example send your message on serail port once and using a timer poll the serial port. By this way your application will not be blocked.

I think it is the only way to take ...

Zubin Sethna
October 13th, 1999, 01:58 AM
I was looking for a better way but like you I think a timer in the application message loop is the only solution for Windows 3.1


Thanks

Zubin

October 13th, 1999, 03:58 AM
do you have tried to process the WM_COMMNOTIFY message in DefWindowProc methode?

Zubin Sethna
October 13th, 1999, 06:45 PM
WM_COMMNOTIFY is buggy as hell on Win 3.1 and eventually stops working. There is a bug report about it on the libraries disk in the Visual C++ 6 package.

cubus
March 16th, 2003, 03:43 AM
In this case it is better to put serial pooling code into separated thread, and make some kind of callback functions that will be called by this thread when new data will be received.
Or, as was told before, perform an ansynchronous communication oriented on different events, overlapped structures etc.