I have code a program which will communicate between 2 process . At the server side , the code phase is as follows :
Static int quitFlag =1;
int main ()
{
int eThreadPoolHandle ;
HANDLE pipeHandle ;
int wThreadID ;
�.
CmtNewThreadPool (EGN_THREAD_NUM, &eThreadPoolHandle); //Create a thread pool
//Create a named pipe
pipeHandle=CreateNamedPipe(DATA_PIPE,PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|PIPE_WAIT, AVAILABLE_PIPE_NUM,0, 0, INFINITE,NULL);
//Spawn a thread to monitor the connect from client side
CmtScheduleThreadPoolFunction (eThreadPoolHandle, WaitForConnectAsk, pipeHandle, &wThreadID);
�..
//When received the quit message , then do follows
CmtDiscardThreadPool (eThreadPoolHandle);
��
Ret
urn 0 ;
}
//The thread using to monitor the client�s call
int CVICALLBACK WaitForConnectAsk (void *functionData)
{
HANDLE pipeHandle ;
pipeHandle = functionData ;
while (quitFlag)
{
if(ConnectNamedPipe(pipeHandle,NULL))// Once there is a connect call , then execute the task
{
/* doing something */
���.
DisconnectNamedPipe(pipeHandle);
}
Sleep(300);
}
CloseHandle(pipeHandle);
return 0;
}
The problem is when execute the sentence "ConnectNamedPipe(pipeHandle,NULL)" , it will always wait for the client call , any belows sentence will not be executed . So when press the Quit button on the panel , I need finish the thread first but it seems not has any method to perform the task . Anyone can advise me how to terminate the thread ? Thanks.
David