Home > Software engineering >  MFC to create threads, the mouse to click interface will be stuck
MFC to create threads, the mouse to click interface will be stuck

Time:09-26

The following create threads,
 
DWORD threadId_encode=0;
HANDLE hthrd_encode=NULL;

Decode_thread_flag=TRUE;

Hthrd_encode=CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) Thread_stream, (LPVOID) this, 0, & amp; ThreadId_encode);
If (hthrd_encode==NULL)
{
Printf (" create thread failed \ n ");
}
The CloseHandle (hthrd_encode);
//
The SetTimer (1200, NULL);


Then threads execute inside the while (1), circulation inside a non-blocking way accept UDP packets,

Question, right now, click on the main interface at any position of the dialog box or button, the interface will be stuck, showed no response, why?

CodePudding user response:

UDP can be handled through a variety of SOCKET mode, select, event, based on the MFC csocket ah, you can read data into the thread processing, in addition to select, generally have the notification message to you to read data,
You can get a sleep look at (100), will also card?

CodePudding user response:

reference 1st floor shengliz response:
UDP can be handled through a variety of SOCKET mode, select, event, based on the MFC csocket ah, you can read data into the thread processing, in addition to select, generally have the notification message to you to read data,
You can get a sleep look at (100), will also card?


For the moment only test the sleep, is of no effect

CodePudding user response:

Multiple Threads in the User Interface of http://msdn.microsoft.com/zh-cn/library/ms810439.aspx

CodePudding user response:

From single describe the feeling there is no problem, thread in operation, such as sending a message, or thread interface

CodePudding user response:

Post code Thread_stream

CodePudding user response:

Threads inside the While (1)

CodePudding user response:

See if your thread to execute code, no Sleep () continued CPU resources, leads to the main thread didn't get to the execution, lead to the main interface is stuck

CodePudding user response:

reference 4 floor CKRGD response:
single from describe the feeling there is no problem, thread operation have send a message, or thread interface

+ 1

CodePudding user response:

Your thread function is how to write?

CodePudding user response:

Thread_stream specific code, estimation is recvfrom failure after not Sleep

CodePudding user response:

Only looked at all your code to know where is wrong.
General interface card dead, is certainly did time-consuming operation in the UI thread, or a blocking function in the UI thread.

CodePudding user response:

CodePudding user response:

You could of MFC, are blocked by this thread

CodePudding user response:

All code + 1
  • Related