Click to See Complete Forum and Search --> : Thread termination
FresherMind
July 4th, 2005, 02:09 AM
Hi Guru,s
I used user interface thread for scanning paricular files from system.
Dialog contains cancle button to cancel the scanning . Now i described
the problem , when i click cancel button at time of scanning the control
does not go to main dialog. But contol reached when all scanning
completes. But i doing wrong .On cancle button i used SetTerminate().
thanks in advance
AshwinRao
July 4th, 2005, 02:25 AM
The framework would not have sufficient time to respond (or may have lost the event corresponding) to the cancel request made by the user while it is busy doing another job. To solve this problem call a function where you would use GetMessage/PeekMessage API supplying the API with the handle of the cancel button and checking for messages like WM_LBUTTONDOWN or WM_KEYDOWN everytime just before you scan for the next file.
Regards
Ashwin
humptydumpty
July 4th, 2005, 03:12 AM
check it out
like if your are creating a thread
hThread = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)BackupThreadBoth,this,NULL,&dwThreadId);//
if(hThread==NULL)
{
::MessageBox(NULL, "Can not create thread.", "Error", MB_OK);
return 1;
}
m_objProgressBar.m_XMLPath = m_XMLPath;
if(m_objProgressBar.DoModal() == IDCANCEL)
{
TerminateThread(hThread, 0);
}
terminate thread is going to terminater your thread when cancel condition occurs
in this example i am calling a dialog and on cancel first dialog the control goes to main dialog window
may be this one helps you
if this thread helps you.don't forget to rate
====================
Feel with us bottam high
FresherMind
July 4th, 2005, 06:06 AM
this applicatiion code i got from sites a class derived from CWinThread. handliing all functionality through Event.
then how i resolve my problem?
thanks in advance
Andreas Masur
July 4th, 2005, 06:40 AM
[ Redirected thread ]
Andreas Masur
July 4th, 2005, 06:42 AM
then how i resolve my problem?
Well...by fixing the problem... ;)
Re-read your description...how should we be able to provide any help? I don't know how your code looks like. And this is the place where the error is...thus, it would be helpful to actually show the code (at least the necessary parts)....
humptydumpty
July 4th, 2005, 06:59 AM
Actually what's the problem and what you want to do.
That's not a proble your class is derived from CWinThread.
but what r u doping and in which way that's thw main thing.
as Andreas tols you if you wann proper answere of your question .please tell your exact problem and with code
=====================
Feel with us bottam high
MikeAThon
July 4th, 2005, 01:36 PM
Are any of your windows (like the cancel button) children of windows owned/created by another thread. This is very difficult to accomplish (because of message queue issues), and should be avoided if possible.
Show some code. Or, better yet, make a minimal project that shows your problem and post the project (minus unneeded files like ncb, opt etc)
Mike
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.