Hi Gurus!

I've got a problem with canceling WaitCommEvent() under windows 2000. This piece of code below works fine under win95.

Im creating several threads, one for each com port to listen to.

Below you can find the method DoJob wich is in the thread. It contains the WaitCommEvent function. Also in the thread a method called End.

And it is in the End method that I want to cancel the waitcommevent. If I just triy to destroy the thereads the threads wont terminate until waitcommevent cancels. So I tried to use SetCommMask to cancel. This works fine under win95 but now I want the program to work on win 2000.

I've tried SetCommMask, PurgeComm, TransmitCommChar. Nothing works. The program just hangs whenever I'm using the comport handler.

Any ideas?
/Andreas

void CListenThread:oJob()
{
DWORD dwErrorFlags, dwEvtMask = 0;
COMSTAT ComStat;
char sBuffer[128];

OVERLAPPED overlapped;
memset(&overlapped,0,sizeof(overlapped));
overlapped.hEvent = CreateEvent(
NULL, // no security attributes
TRUE, // auto reset event
FALSE, // not signaled
NULL // no name
);

m_sFilterList[0] = "NONE";
m_sFilterList[1] = "RP570";
m_sFilterList[2] = "R4E2";
m_sFilterList[3] = "RIP";
m_sFilterList[4] = "ASCII";
m_sFilterList[5] = "HEX";

CString sFormatedSerialPort;
sFormatedSerialPort.Format("\\\\.\\%s", m_sSerialPort);

/* CONNECT TO SERIAL PORT */
m_tComm = CreateFile( sFormatedSerialPort,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);

/* CHECK IF SELECTED PORT EXISTS OR IS IN USE*/
if (m_tComm == INVALID_HANDLE_VALUE)
{
//CAN DISPLAY ERROR MSG HERE
}
else
{
SetPortState();

/* SET WHAT TO WAIT FOR "EV_RXCHAR = A character was received and placed in the input buffer. " */
::SetCommMask(m_tComm, EV_RXCHAR);

::SetupComm(m_tComm, 4096, 4096);

::PurgeComm(m_tComm, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RX CLEAR);

while (1)
{

WaitCommEvent(m_tComm, &dwEvtMask, &overlapped);

::ClearCommError(m_tComm, &dwErrorFlags, &ComStat);
DWORD dwLength = min((DWORD)MAX_RXBLOCK, ComStat.cbInQue);

/* READ FROM SERIAL PORT. PLACES IN sBuffer */
BOOL bReadStat = ReadFile ( m_tComm, &sBuffer, dwLength, &dwLength, &overlapped);



**********************************'

void CListenThread::End()
{
//Cancel WaitCommEvent()
SetCommMask ( m_tComm, 0 ) ;

//Close handle to comport
CloseHandle(m_tComm);
}