|
I'm having some trouble making a thread I have exit nicely. The thread function looks like:
UINT tBeginCommunication (LPVOID pParam) {<br />
t_commPackage * commPackage = (t_commPackage*) pParam;<br />
while (commPackage->cmdStopThread) {<br />
... do thread work here ...<br />
}<br />
commPackage->haveStoppedThread = true;<br />
AfxEndThread(0, false);<br />
return 0;<br />
}
When I want to stop the thread, I have this:
m_serialPortData->cmdStopThread = true;<br />
while (!(m_serialPortData->haveStoppedThread));
It signals to stop the thread, and waits until the thread has stopped.
The problem is that the while loop in the controlling function is never exited, it hammers the CPU and therefore the OS, I need to end the process via Task Manager to get back control. The data is not deleted because of the false argument in the AfxEndThread call so the main function has a chance to read it in the while.
I know I must be missing some thread nuance everyone else knows so please let me know what I'm not doing right. Thanks in advance, Nate.
|
|
|
|
|
Instead of looping over a variable, loop over until you get a signal that says you are done. Something like
while (1)
{
signalledObject = WaitForMultipleObjects(...);
if (signalledObject = THREAD_QUIT)
break;
// Do your job
}
Regards
Senthil
My Blog
|
|
|
|
|
See here for tips on how to properly shut down a thread.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks, that helped a lot. I looked at that page and it showed me better ways of starting and ending the thread nicely. I wanted to use a timeout somehow before I knew about the event handles and signals so this solution works out very nicely. Deriving my class from CWinThread would have been overkill because I don't need that much control but knowing I can do that is good to know. I ended up making 3 handles to signals, one to signal a good start from the thread to the main app, one to signal from the main app to the thread to stop, and one last signal to tell the main app the thread finished and it works nicely. Thanks again for the excellent link, Nate.
|
|
|
|
|
Dear Friends,
I want to write an application which monitors all opened TCP/UDP ports on the local computer. Also i want to map those ports to owning applications, in order to determine which process has opened which port. There is an IP Helper API function GetTCPTable() , but it does not tell about the process. In Windows XP there is an undocumented API AllocateAndGetTCPExTableFromStack() which suits my needs. But i also want to support Win2K Operating system.
Please tell me is there any API which can helps me or any suggestion.
Imtiaz
|
|
|
|
|
hi,
how to load an image in the mainframe window's client area in a MDI application.
thanks
Cool Ju
|
|
|
|
|
|
|
Hi
I am working with FormView in SDI VC++ application. On my CForm view, I have many graphs and data displayed on it. I have to save the entire contents that are displayed on the CFormView as it is into .jpg or a .bmp file. Can any one suggest a method to do this.
Thanks
Madhavi
|
|
|
|
|
Draw your graphs and data onto a memory DC. That memory DC has an HBITMAP that can be saved to a file, there are articles on this site that explain how. You can then also BitBlt that memory DC to a control on your form for display.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
I have some buttons and list controls on the view. I should be able to save all that is displayed on the form view to bmp or jpeg file, in order words the bmp or jpeg file should just be a snaposhot/printscreen of the CFormView. By using memdc, I can just save the drawings. Can you please suggest a method to do this.
|
|
|
|
|
Thanks for the suggestion.
By using memdc, I can only save all that is drawn using the DC.I have some buttons and list controls on the view. I should be able to save all that is displayed including the controls on the form view to bmp or jpeg file, in order words the bmp or jpeg file should just be a snaposhot/printscreen of the CFormView. Can you please suggest a method to do this.
|
|
|
|
|
Search this site for "Screen capture", there are many articles that cover the topic.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
who has this head file,pls send it to me,thanks a lot!
My E-mail: sfm_rat@163.com
|
|
|
|
|
Sure - let me just whip it up for you.
Seriously, I am concerned how often people ask a question like this.
1. where does this file come from ?
2. don't you realise that a header file is just the beginning of the food chain ? This header will probably need a .cpp file to actually do anything, and more likely is distributed with a .lib file that you'll need to link to in order for your compiled code to actually be able to link to the functionality the header is describing.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
But CG, first error is always blabla.h not found . They will start looking for lib once they find header
"Aerodynamically, the bumble bee shouldn't be able to fly, but the
bumble bee doesn't know it so it goes on flying anyway." - Mary Kay Ash
My Articles
|
|
|
|
|
|
|
I'm trying to write a program in C, which encode an image (ex: *.Jpeg) into DICOM (Digital Imaging and Communications in Medicine) file and decode image data from Dicom file to an visible image, but I donot know the algorithm to do this. Could you tell me about this algorithm. Thanks alot!
Sincerely
Thangnvhl
|
|
|
|
|
DICOM is more than an image, it stores metadata about the image as well. There are specs that are easily found with google, but the fact that several libraries charge between $2000 and $5000 for code to read/write DICOM, I'd imagine a really compliant library is a fairly big job.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks for your reply. I known DICOm is more than an image. But now i'm trying to put an jpeg file into a DICOM file. So i want to know how to do this. Do you know any document which tell about this? Show me please! Thanks!
Sincerely
Thangnvhl
|
|
|
|
|
|
Hi guys, I'm writing a Spell Checker Add-in for Microsoft Word. Does anyone have any hints or tips. Is there any algorithm available or stuff like that?
|
|
|
|
|
erm.... Word comes with a spell checker. Thanks for the laugh tho.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
http://www.codeproject.com/editctrl/SpellEdit.asp[^] has info on using a spell checker in an edit control. It also has a link to a spell checker engine. It may be of some use to you.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|