Click here to Skip to main content
15,905,563 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: 880228 - taking time in handling stops responding Pin
norish17-May-09 21:29
norish17-May-09 21:29 
If your calculation is just a calculation and never refers any other resources,
I recommend the calculation is to be a thread and dialog button kickes start and stop only.
I figure it very simply like belows.

unsinged __stdcall calculation(void*)
{
 // start real calculation
}

void CMyDialog::OnStart() {
 m_threadHandle = (HANDLE)_beginthreadex(NULL, 0, calculation, NULL, 0, &m_threadId);
};

void CMyDialog::OnCancel() {
 if (m_threadHandle) {
  TerminateThread(m_threadHandle, 0x13);
  CloseHandle(m_threadHandle);
 }
};


Consider the calculation() must be thread-safe and makes no resource leaks.

If your calculation refers some other resources and should not be killed by TerminateThread(), another method is a stop flag refernce inside a loop.

like;
void calc(bool volatile f_stop) {
 for () {
  for () {
   for () {
    if (f_stop) goto exit_all_loop;
   }
  }
 }
exit_all_loop:
 // clean up all resources
}


The function calc() is to be well designed at a point of cleaning up and performance trade-off.
GeneralRe: 880228 - taking time in handling stops responding Pin
ilostmyid218-May-09 0:09
professionalilostmyid218-May-09 0:09 
AnswerRe: 880228 - taking time in handling stops responding Pin
norish18-May-09 0:33
norish18-May-09 0:33 
GeneralRe: 880228 - taking time in handling stops responding Pin
ilostmyid218-May-09 1:02
professionalilostmyid218-May-09 1:02 
Question[Message Deleted] Pin
zakkas248317-May-09 20:01
zakkas248317-May-09 20:01 
AnswerRe: Custom Tree Control win32 Pin
_AnsHUMAN_ 17-May-09 20:11
_AnsHUMAN_ 17-May-09 20:11 
GeneralRe: Custom Tree Control win32 Pin
zakkas248317-May-09 20:35
zakkas248317-May-09 20:35 
QuestionHow to Segment the characters ? Pin
Sakthi.Gs :-)17-May-09 19:01
Sakthi.Gs :-)17-May-09 19:01 
AnswerRe: How to Segment the characters ? Pin
Cedric Moonen17-May-09 20:55
Cedric Moonen17-May-09 20:55 
QuestionHow to Segment the characters ? Pin
Sakthi.Gs :-)17-May-09 21:27
Sakthi.Gs :-)17-May-09 21:27 
AnswerRe: How to Segment the characters ? Pin
CPallini17-May-09 21:31
mveCPallini17-May-09 21:31 
QuestionHow to Segment the characters ? Pin
Sakthi.Gs :-)17-May-09 21:47
Sakthi.Gs :-)17-May-09 21:47 
QuestionHow to Segment the characters [ Image Processing] ? Pin
Sakthi.Gs :-)17-May-09 21:50
Sakthi.Gs :-)17-May-09 21:50 
GeneralRe: How to Segment the characters [ Image Processing] ? Pin
norish18-May-09 5:43
norish18-May-09 5:43 
QuestionRe: How to Segment the characters ? Pin
CPallini17-May-09 21:57
mveCPallini17-May-09 21:57 
QuestionHow to Segment the characters ? Pin
Sakthi.Gs :-)17-May-09 22:34
Sakthi.Gs :-)17-May-09 22:34 
Questionprint unicode number in c++ Pin
pitok23514917-May-09 18:31
pitok23514917-May-09 18:31 
AnswerRe: print unicode number in c++ Pin
CPallini17-May-09 22:18
mveCPallini17-May-09 22:18 
QuestionRetrieving public key for encryption from digital certificate Pin
shrims4u17-May-09 5:25
shrims4u17-May-09 5:25 
Questionclick 'enter' button make text in CEdit control to get next line Pin
jeansea17-May-09 4:51
jeansea17-May-09 4:51 
AnswerRe: click 'enter' button make text in CEdit control to get next line Pin
Code-o-mat17-May-09 4:58
Code-o-mat17-May-09 4:58 
GeneralRe: click 'enter' button make text in CEdit control to get next line Pin
jeansea17-May-09 5:41
jeansea17-May-09 5:41 
GeneralRe: click 'enter' button make text in CEdit control to get next line Pin
Code-o-mat17-May-09 5:55
Code-o-mat17-May-09 5:55 
GeneralRe: click 'enter' button make text in CEdit control to get next line Pin
jeansea17-May-09 6:02
jeansea17-May-09 6:02 
GeneralRe: click 'enter' button make text in CEdit control to get next line Pin
N a v a n e e t h17-May-09 7:11
N a v a n e e t h17-May-09 7:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.