I create a thread CreateThread and through it I update the contents of the element in the program. But the update rate is very small, 1 time in 15 seconds. How to make a thread not dependent on the program? At the request of those who wish, I will describe everything in more detail: If you create a stream, it will display a message at high speed in this way:

char *dwThrdParam = "Hello!"; DWORD dwThreadId; HANDLE hThread = CreateThread(0, 0, UpdateList, dwThrdParam, 0, &dwThreadId); ....... DWORD WINAPI UpdateList(LPVOID lParam) { int c = 0; for (;;) { UpdateProcessList(listView, Process); char b[20]; sprintf_s(b, "%s, %d\n",(char*)lParam, c); OutputDebugString(b); c++; } return 0; } 

But when in a cycle not a flow !!! And I start writing programs that reduce the number of loop passes from several thousand to 30 times per second, then the thread starts displaying the message every 15 seconds. Here is the program loop code:

 VSync.Begin(30); while (globalRunning) { if (PeekMessage(&message, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&message); DispatchMessage(&message); } VSync.End(false); } 

Vsync is based on sleep. An interesting feature if you start to move the window for the title, the flow rate increases many times. For those who are sure that the calculation is:

 char buffer[256]; LVITEM lvi; memset(&lvi, 0, sizeof(lvi)); lvi.mask = LVIF_TEXT | LVIF_TEXT; for (int i = 0; i < 10; i++) { lvi.iItem = i; lvi.iSubItem = 0; ListView_InsertItem(listView, &lvi); sprintf_s(buffer, "%d", i); ListView_SetItemText(listView, currentItem, lvi.iSubItem, buffer); } 
  • one
    What do you mean by independence from the program? - Pavel Mayorov
  • one
    Well, maybe the content calculation for an item takes 15 seconds? - KoVadim
  • 2
    Need more details. Threads work asynchronously with respect to the program itself, if you yourself did not synchronize. - Vladimir Martyanov
  • one
    There is no “calculation” space in the code above. PeekMessage - it can block threads before receiving messages. If you move the window - events are generated, PeekMessage works "quickly". Further I hope it is clear. - KoVadim
  • one
    Inside the loop, you are trying to insert items into the list. And did not think that it also uses messages. And as a result, it seems that you are blocking yourself. - KoVadim

0