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 -
typedef struct my_TNFO
-
{
-
HANDLE h_event;
-
HANDLE h_thread;
-
DWORD thread_id;
-
BOOL running;
-
BOOL init;
-
BOOL canceled;
-
} TNFO;
-
-
...
-
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(...);
-
...
-
}
-
...
-
the thread function actually calls a recursive directory parser function. I've set it up as -
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;
-
}
in the recursive function, I've tried both Send and PostMessage. -
...
-
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);
-
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_DELETEALLITEMS.
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
I guess you would save the current tab in a stack. You could pop/push around the various tabs.
4 1523
OK. You have created an event object and a thread object and the thread is listening for an event. Where is the event?
I think you need to call SetEvent to put your event object into the signaled state. Otherwise, WaitForSingleObject will hear nothing.
Thank you for the reply... as always, I appreciate your time and feedback.
The problem went away after moving the (tmp->canceled == TRUE) test to the bottom of the do-while. I still have no clue as to way the program bogged down if that test was at the top of the loop.
SetEvent was called within one of the WM_USER messages. The thread ended, but had a sort of delayed effect before. Moving the canceled test "fixed it."
Do you know of a way store the previously selected tab of a tab control? All I can get is the current selection, which isn't helpful for what I need to do.
TIA
I guess you would save the current tab in a stack. You could pop/push around the various tabs.
I wish that I could learn to think like a programmer; thank you for that! Just what it needed. :)
Cheers
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Doe |
last post by:
Hi all,
I know the standard doesn't care about threads (wrongly :-)
But in current compilers implementation, is the "list" which holds count
of the occupied and free heap addresses SHARED among...
|
by: Gionni |
last post by:
I have to translate this code in VB6 in C#:
Declare Function OpenEvent Lib "kernel32.dll" Alias "OpenEventA" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal lpName As...
|
by: J.Marsch |
last post by:
Issue:
I have 3 threads, syncing with a ReaderWriterLock (in "real life", there
will be more).
Thread 1 (there could be any number of these) Gets a read lock with infinite
timeout. It runs in...
|
by: Hardy Wang |
last post by:
Hi,
I have a windows form application, and there are 2 buttons in the form. In
first button's click event I have code like:
Thread t = new Thread(new ThreadStart(fileProcessor));
t.Start();
To...
|
by: Stephen Miller |
last post by:
I have an ASP.Net application that sends a NetworkStream to a .Net
Service, which has a TcpListener listening on a port for the ASP.Net
client. When it receives a request it creates a new thread...
|
by: k.mellor |
last post by:
Hi,
I hope someone can help. I have written a simple form to demonstrate
my problem/question. The code follows.
The form starts a thread, which using delegates updates a label (Every
second...
|
by: Martin Evans |
last post by:
I know this has been seen before but it is not making too much sense (after
reading many posts). It all appears to work fine but then dies after about
40 invocations.
My app has Python embedded,...
|
by: Donos |
last post by:
Hi
I have a HANDLE to an Event, like this..
HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL);
This is running in one thread in one class. For example we will call
that class as "Class A"...
|
by: NvrBst |
last post by:
I've read a bit online seeing that two writes are not safe, which I
understand, but would 1 thread push()'ing and 1 thread pop()'ing be
thread-safe? Basically my situation is the follows:
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |