<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:PMingLiU;
        panose-1:2 2 3 0 0 0 0 0 0 0;}
@font-face
        {font-family:PMingLiU;
        panose-1:2 2 3 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@PMingLiU";
        panose-1:2 2 3 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-NZ link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>I think now from memory, the problem was someone clicking a button while in the sleep loop. It was rare but was causing some sort of deadlock. What I could try is to set the mainform.enabled := false at the top of the procedure and enable at the bottom to prevent that situation and put Application.ProcessMessages back. I’ll give that a go.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Cheers.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Ross Levis [mailto:ross@stationplaylist.com] <br><b>Sent:</b> Tuesday, 15 May 2012 3:02 p.m.<br><b>To:</b> 'NZ Borland Developers Group - Delphi List'<br><b>Subject:</b> RE: [DUG] Hang during Sleep<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>I was using ProcessMessages in the sleep loop but it was causing problems and was removed. I don’t recall the problem now but I think some event was being executed while in the loop and caused some problem. I went to some trouble to not use it as you will see below.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>But I might try adding it back for this user and see if it helps.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Here is the procedure the sleep function is in.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'>procedure StudioForm.LoopSleep(Duration: Integer);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'>var<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> TickCount, LastCount, StartCount: Cardinal;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> TimerStatus: Boolean;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> Msg: TMsg;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'>begin<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> TimerStatus := Timer.Enabled;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> Timer.Enabled := False;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> TickCount := GetTickCount;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> StartCount := TickCount;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> LastCount := TickCount;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> while GetTickDiff(StartCount,TickCount) <= Duration do<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> begin<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> Sleep(5);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> if GetTickDiff(LastCount,TickCount) >= 20 then // update every 20ms<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> begin<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> LastCount := TickCount;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> TimerTimer(nil); // update elapsed, VU, etc<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> PeekMessage(Msg, StudioForm.Handle , 0, 0, PM_NOREMOVE); // tells Windows 7 app is not hung<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> StudioForm.Update;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> end;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> TickCount := GetTickCount;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> end;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'> Timer.Enabled := TimerStatus;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt'>end;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>GetTickDiff is a small Indy function which handles the situation if the tick count rolls over to 0 after 49 days.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Regards,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Ross.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> <a href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a> [<a href="mailto:delphi-bounces@listserver.123.net.nz">mailto:delphi-bounces@listserver.123.net.nz</a>] <b>On Behalf Of </b>Pieter De Wit<br><b>Sent:</b> Tuesday, 15 May 2012 5:26 a.m.<br><b>To:</b> NZ Borland Developers Group - Delphi List<br><b>Subject:</b> Re: [DUG] Hang during Sleep<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>Ross Levis <<a href="mailto:ross@stationplaylist.com">ross@stationplaylist.com</a>> wrote:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Hi Pieter<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Bugreport.txt is attached.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>It is a media player, and there are short pauses in some areas, such as to wait for the player process to come back from executing a command before executing another one.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>The player itself is a separate process controlled by this one using shared memory.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>The sleep is in a procedure which loops around for a set period (100ms in this case) with a sleep(5) and a MainForm.Update so VU meters continue moving.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Cheers,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Ross.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> <a href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a> [<a href="mailto:delphi-bounces@listserver.123.net.nz">mailto:delphi-bounces@listserver.123.net.nz</a>] ! <b>On Behalf Of </b>Pieter De Wit<br><b>Sent:</b> Monday, 14 May 2012 9:47 p.m.<br><b>To:</b> NZ Borland Developers Group - Delphi List; 'NZ Borland Developers Group - Delphi List'<br><b>Subject:</b> Re: [DUG] Hang during Sleep<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>Ross Levis <<a href="mailto:ross@stationplaylist.com">ross@stationplaylist.com</a>> wrote:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Perhaps someone can offer some clues to the problem. A user is experiencing a hang during a Sleep(5) function! It’s Win7 64-bit Hyperthreaded Intel 4 core CPU.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>With MadExcept, it is showing the following…<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>! <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Courier New"'>exception message : The application seems to be frozen.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Courier New"'>main thread ($9f4):<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Courier New"'>771dfd6a ntdll.dll NtDelayExecution<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Courier New"'>75ce31b5 KERNELBASE.dll SleepEx<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Courier New"'>75c! e3a86 KERNELBASE.dll Sleep<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Courier New"'>005dc66b SPLStudio.exe StudioMain 6808 +9 LoopSleep<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>3 known threads are sitting at a Synchronize/NtWaitForSingleObject waiting for the current procedure in the main form to finish, which is sitting at Sleep(5). I would expect that.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Another thread is also sitting at NtWaitForSingleObject but it doesn’t say what the thread class name is so not sure what ! it is.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Another unknown thread is at NtWaitForMultipleObjects.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>And another unknown t! hread is at NtWaitForWorkViaWorkerFactory.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>I know about the 3 threads waiting at Synchronize, but they shouldn’t be a problem. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>What can cause a Sleep(5) to hang for over 90 seconds?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>I can send the full bugreport.txt file if useful.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Thanks,<o:p></o:p></span></p><p class=MsoNormal>Ross.<o:p></o:p></p></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><br clear=all>Hi Ross,<br><br>Bugreport.txt will be usefull plus a short desc as to why you sleeping and what the app is waiting for?<br><br>Cheers,<br><br>Pieter<br><br>-- <br>Sent from my Android phone. Please excuse my brevity.<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><br clear=all>Hi Ross,<br><br>I view you bug report on my mobile, so i might have missed it, but run application.processmessage (); before your sleep and after as well.<br><br>Cheers<br><br>Pieter<br>-- <br>Sent from my Android phone with K-9 Mail. Please excuse my brevity.<o:p></o:p></span></p></div></body></html>