|
-
Apr 2nd, 2002, 01:40 AM
#1
Thread Starter
Junior Member
Multi-Threading - Stopping A Thread?
Alrighty, I'm understanding threads alot more than I was before heheh but here's my next hurdle. I created a thread and got it working fine but now I can't figure out how to stop it. I would like the thread to stop running when I click on the quit button I have setup.
case ID_QUITBTN:
?
break;
-
Apr 2nd, 2002, 11:14 AM
#2
Frenzied Member
Can you post the code of how you are getting the thread to fire
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Apr 2nd, 2002, 01:58 PM
#3
Usually you pass a flag (e.g. a BOOL variable) inside the thread's params. The thread should repeatedly check this flag - if it is set, the thread returns.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 2nd, 2002, 02:39 PM
#4
Thread Starter
Junior Member
PHP Code:
// Here's where the function's at.
void APICallAction()
{
// API Calls here
}
// Here's where I fire off the thread.
case ID_ACTIONBTN:
HANDLE APICallThread;
DWORD threadID;
APICallThread=CreateThread(0, 0, (LPTHREAD_START_ROUTINE) APICallAction, 0, 0, &threadID);
break;
Need anything else?
-
Apr 3rd, 2002, 06:46 AM
#5
The prototype of the thread func must be
void Name (LPVOID);
no matter whether you use the argument or not. Otherwise you just might get serious problems. And it saves you from having to cast to LPTHREAD_START_ROUTINE.
Inside the LPVOID parameter you can pass things to the thread, like here:
Code:
// Here's where the function's at.
void APICallAction(LPVOID pArg)
{
PBOOL pCon = (PBOOL)pArg;
while(*pCon)
{
// Do something here
}
delete pCon;
}
// Here's where I fire off the thread.
case ID_ACTIONBTN:
HANDLE APICallThread;
DWORD threadID;
PBOOL pCon = new BOOL; // save this pointer somewhere
// maybe static in WndProc
*pCon = TRUE;
APICallThread=CreateThread(0, 0, (LPTHREAD_START_ROUTINE) APICallAction, pCon, 0, &threadID);
break;
// When you want the thread to end:
*pCon = FALSE; // thread willl terminate a few milliseconds later
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|