I don't know if I've setup the thread correctly or not, but its behavoir isn't what I'd expect. I'm creating the thread within a BN_CLICKED message
the thread function actually calls a recursive directory parser function. I've set it up as
in the recursive function, I've tried both Send and PostMessage.
progd->count was devised to stop the thread when the recursion ended by posting a message to the main window. When it reaches 1, the def procedure sends the WMU_DISC_DONE message to set the event
All that *appears* to work; however, if I cancel the recursion thread, the list view continues to populate for a bit and then deletels all but 1 item though I send the message LVM_DELETEALLIT EMS.
If I move the (tmp->canceled == TRUE) test inside of the do-while, the app gets loopy. Any idea as to why this behavoir occurs?
If more information is needed, please ask.
TIA
Code:
typedef struct my_TNFO
{
HANDLE h_event;
HANDLE h_thread;
DWORD thread_id;
BOOL running;
BOOL init;
BOOL canceled;
} TNFO;
Code:
...
if(HIWORD(wParam) == BN_CLICKED)
{
memset(&tnfo, 0, sizeof(tnfo));
tnfo.running = TRUE; // thread active
tnfo.init = TRUE; // thread started
tnfo.canceled = FALSE; // user controlled
tnfo.h_event = CreateEvent(NULL, TRUE, FALSE, NULL);
tnfo.h_thread = CreateThread(...);
...
}
...
Code:
DWORD WINAPI threads_ParseDisc(LPVOID lParam)
{
TNFO *tmp = (TNFO *)lParam;
if(tmp->init == TRUE)
{
tmp->init = FALSE;
// call recursive function
}
while(WaitForSingleObject(tmp->h_event, INFINITE) != WAIT_OBJECT_0)
Sleep(1000);
CloseHandle(tmp->h_event);
CloseHandle(tmp->h_thread);
tmp->running = FALSE;
return 0;
}
Code:
...
HANDLE hFind = INVALID_HANDLE_VALUE;
hFind = FindFirstFile(tmp, &wfd);
if(hFind == INVALID_HANDLE_VALUE)
{
PostMessage(hwnd_to_main, WMU_DISC_DONE, 0, 0);
return;
}
if(tmp->canceled == TRUE)
{
PostMessage(hwnd_to_main, WMU_DISC_CANCEL, 0, 0);
return;
}
do
{
// if directory, call self... (path, tnfo);
// if file, populate list view control
} while(FindNextFile(...) != 0);
FindClose(hFind);
++progd->count;
PostMessage(hwnd_to_main, WMU_DISC_COUNT, (WPARAM)0, (LPARAM)(ULONG)progd->count);
All that *appears* to work; however, if I cancel the recursion thread, the list view continues to populate for a bit and then deletels all but 1 item though I send the message LVM_DELETEALLIT EMS.
If I move the (tmp->canceled == TRUE) test inside of the do-while, the app gets loopy. Any idea as to why this behavoir occurs?
If more information is needed, please ask.
TIA
Comment