Click here to Skip to main content
12,953,230 members (47,558 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

18.3K views
4 bookmarked
Posted 20 Apr 2011

Alternate to Thread.Sleep

, 27 Apr 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
I coded this small stub to waste time as an alternate to Thread.Sleep:
private void WasteTime(TimeSpan unit)
{
  DateTime now = DateTime.Now;
  DateTime then = DateTime.Now + unit;
 
  while (now < then)
  {
    now = DateTime.Now;
  }
}


Works quite preceisely.

private void WasteTime(TimeSpan unit)
{
  DateTime then = DateTime.Now + unit;
  while (DateTime.Now < then)
  {;}
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

reachme_saurabh
Web Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 1 Wastes CPU cycles Pin
Member 798323829-Jul-11 8:26
memberMember 798323829-Jul-11 8:26 
GeneralTime has passed (i was waiting :-)) now I found the word for... Pin
johannesnestler2-May-11 2:15
memberjohannesnestler2-May-11 2:15 
GeneralThe only time I needed something like this code was when I h... Pin
Adis H.28-Apr-11 2:24
memberAdis H.28-Apr-11 2:24 
GeneralPointless Pin
Nagy Vilmos28-Apr-11 0:48
memberNagy Vilmos28-Apr-11 0:48 
GeneralThere is difference between : DateTime waitForDating = DateT... Pin
Rajin Sayeed S Alam27-Apr-11 22:02
memberRajin Sayeed S Alam27-Apr-11 22:02 
GeneralThis is a fantastic example... of what to never do! Pin
AspDotNetDev27-Apr-11 10:49
protectorAspDotNetDev27-Apr-11 10:49 
GeneralThis blocks, so why call it? Pin
Greg Osborne27-Apr-11 7:10
memberGreg Osborne27-Apr-11 7:10 
GeneralTry Thread.SpinWait(1000000000) for a change. Pin
Kerem Kat27-Apr-11 5:36
memberKerem Kat27-Apr-11 5:36 
GeneralYes, I'd call it WastTimeAndCPUAndPower :-) Pin
johannesnestler21-Apr-11 3:44
memberjohannesnestler21-Apr-11 3:44 
GeneralRe: Of course. I agreed with above two comments. Whatever the im... Pin
CodingLover27-Apr-11 23:23
memberCodingLover27-Apr-11 23:23 
GeneralBut you do realize that they are not the same right? Because... Pin
Karthik. A20-Apr-11 16:34
memberKarthik. A20-Apr-11 16:34 
GeneralPointless and Inefficeint Pin
Nagy Vilmos28-Apr-11 0:45
memberNagy Vilmos28-Apr-11 0:45 
GeneralWhy? Pin
Andrew Rissing20-Apr-11 3:58
memberAndrew Rissing20-Apr-11 3:58 
GeneralCPU hog Pin
Indivara20-Apr-11 2:29
subeditorIndivara20-Apr-11 2:29 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170525.1 | Last Updated 27 Apr 2011
Article Copyright 2011 by reachme_saurabh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid