Click here to Skip to main content
15,909,953 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: a problem about ListBox's item Pin
Chen-XuNuo22-Mar-07 3:41
Chen-XuNuo22-Mar-07 3:41 
AnswerRe: a problem about ListBox's item Pin
CPallini22-Mar-07 2:46
mveCPallini22-Mar-07 2:46 
GeneralRe: a problem about ListBox's item Pin
Chen-XuNuo22-Mar-07 3:13
Chen-XuNuo22-Mar-07 3:13 
GeneralRe: a problem about ListBox's item Pin
CPallini22-Mar-07 3:38
mveCPallini22-Mar-07 3:38 
GeneralRe: a problem about ListBox's item Pin
Chen-XuNuo22-Mar-07 3:44
Chen-XuNuo22-Mar-07 3:44 
GeneralRe: a problem about ListBox's item Pin
Chen-XuNuo22-Mar-07 3:24
Chen-XuNuo22-Mar-07 3:24 
GeneralRe: a problem about ListBox's item Pin
CPallini22-Mar-07 3:47
mveCPallini22-Mar-07 3:47 
QuestionSetTimer critical section problem Pin
D G McKay22-Mar-07 1:35
D G McKay22-Mar-07 1:35 
I have a class which sets a timer to fire every five minutes:

m_hTimer = ::SetTimer(NULL, NULL, 5*60*1000, MyTimerProc);

Dependent on circumstances, MyTimerProc() may need to ask for user intervention (for simplicity I'll use an AfxMessageBox()). Obviously I don't want the AfxMessageBox to pop up multiple times should the program be unattended for a period of time. I have come up with the following:

void CALLBACK MyTimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)<br />
{<br />
   static bool locked = false;<br />
<br />
   if (!locked)<br />
   {<br />
      locked = true;<br />
      AfxMessageBox("HELLO");<br />
      locked = false;<br />
   }<br />
}


Of course, I'd rather be using something safer than the frankly dodgy static variable. But EnterCriticalSection() et al don't work (they merely increment the LockCount and RecursionCount without blocking), and the CreateMutex()/WaitForSingleObject() method seems to suffer from the same problem.

I think the problem is down to each successive SetTimer() event being seen as being in the same thread.

Anybody been here before? Any suggestions gratefully received!
AnswerRe: SetTimer critical section problem Pin
James R. Twine22-Mar-07 1:46
James R. Twine22-Mar-07 1:46 
AnswerRe: SetTimer critical section problem Pin
kakan22-Mar-07 1:55
professionalkakan22-Mar-07 1:55 
GeneralRe: SetTimer critical section problem Pin
James R. Twine22-Mar-07 2:09
James R. Twine22-Mar-07 2:09 
GeneralRe: SetTimer critical section problem Pin
kakan22-Mar-07 2:19
professionalkakan22-Mar-07 2:19 
GeneralRe: SetTimer critical section problem Pin
D G McKay22-Mar-07 2:30
D G McKay22-Mar-07 2:30 
GeneralRe: SetTimer critical section problem Pin
kakan22-Mar-07 2:34
professionalkakan22-Mar-07 2:34 
AnswerRe: SetTimer critical section problem Pin
Parthi_Appu22-Mar-07 1:57
Parthi_Appu22-Mar-07 1:57 
GeneralRe: SetTimer critical section problem Pin
Michael Dunn22-Mar-07 10:14
sitebuilderMichael Dunn22-Mar-07 10:14 
GeneralRe: SetTimer critical section problem Pin
Parthi_Appu22-Mar-07 17:06
Parthi_Appu22-Mar-07 17:06 
AnswerRe: SetTimer critical section problem Pin
Stephen Hewitt22-Mar-07 13:00
Stephen Hewitt22-Mar-07 13:00 
QuestionCheck if is folder or file function? Pin
bosfan22-Mar-07 0:51
bosfan22-Mar-07 0:51 
AnswerRe: Check if is folder or file function? Pin
prasad_som22-Mar-07 0:54
prasad_som22-Mar-07 0:54 
GeneralRe: Check if is folder or file function? [modified] Pin
bosfan22-Mar-07 0:57
bosfan22-Mar-07 0:57 
QuestionRe: Check if is folder or file function? Pin
Rajesh R Subramanian22-Mar-07 0:58
professionalRajesh R Subramanian22-Mar-07 0:58 
AnswerRe: Check if is folder or file function? Pin
David Crow22-Mar-07 3:06
David Crow22-Mar-07 3:06 
GeneralRe: Check if is folder or file function? Pin
Rajesh R Subramanian22-Mar-07 3:18
professionalRajesh R Subramanian22-Mar-07 3:18 
GeneralRe: Check if is folder or file function? Pin
David Crow22-Mar-07 3:23
David Crow22-Mar-07 3:23 

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.