Article 1X1Z8 CodeSOD: Non-Threading

CodeSOD: Non-Threading

by
Ellis Morning
from The Daily WTF on (#1X1Z8)

512px-Silk_Yarn_%283538527583%29.jpg

Reader Tyler shares this outstanding example of thread evasion:

Apparently they needed a way to delay current execution but still process window messages, and running it in a separate Thread and calling Sleep() would have been too hard ... Thankfully this function isn't actually being used anymore, and has been canned from the repo.

Thankfully, indeed. Come for the honest commenting, stay for the funky definition of one second, the adding of seconds that I think is supposed to represent real time ticking by as the function runs, the countup (countdowns are lame), and the invocation of Application.DoEvents(), a holdover from Visual Basic. Seeing as this is a VB.NET app, it's probably not the best way to allow other processes and events to run, but there are differing opinions on this.

 ''NEVER USE THIS FUNCTION, it is full of evil and it will come to haunt you.... Public Shared Sub Delay(ByVal dblSecs As Double) Const OneSec As Double = 1.0# / (1440.0# * 60.0#) Dim dblWaitTil As Date Now.AddSeconds(OneSec) dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(dblSecs) Do Until Now > dblWaitTil Application.DoEvents() ' Allow windows messages to be processed Loop End Sub
otter-icon.png [Advertisement] Infrastructure as Code built from the start with first-class Windows functionality and an intuitive, visual user interface. Download Otter today! TheDailyWtf?d=yIl2AUoC8zAdaiUAsCxCi4
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments