Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
GeneralRe: accessing controls through a collection Pin
Furty24-Jul-03 15:15
Furty24-Jul-03 15:15 
GeneralRe: accessing controls through a collection Pin
LongRange.Shooter29-Jul-03 8:35
LongRange.Shooter29-Jul-03 8:35 
GeneralThread.Sleep is too slow Pin
eggie524-Jul-03 10:26
eggie524-Jul-03 10:26 
GeneralRe: Thread.Sleep is too slow Pin
albean24-Jul-03 10:30
albean24-Jul-03 10:30 
GeneralRe: Thread.Sleep is too slow Pin
eggie524-Jul-03 11:35
eggie524-Jul-03 11:35 
GeneralRe: Thread.Sleep is too slow Pin
albean24-Jul-03 14:26
albean24-Jul-03 14:26 
GeneralRe: Thread.Sleep is too slow Pin
eggie524-Jul-03 17:36
eggie524-Jul-03 17:36 
GeneralRe: Thread.Sleep is too slow Pin
albean25-Jul-03 9:09
albean25-Jul-03 9:09 
Eggie,

You need to read about the Thread.Sleep method and more importantly what a context switch is.

Sleep( X ) means the thread will not be scheduled for execution by the operating system for X milliseconds. Sleep(0) causes the thread to be suspended (a context switch) and immediately rescheduled for another time slice. If there are no other threads at your thread’s priority level then it is executed.

The bottom line is you will not be able to create a delay to the precision you are looking for. (Well, you might be able to with in-line assembly but a context switch could occur and make the “delay” longer. And, now that I think about it, you will probably have to boost your thread’s priority. ) Sleep(0) is the shortest delay that I can think of but there is no control over its duration. Since there will be other threads waiting, they will all execute their time slices before yours gets the CPU back. I don’t recall what Microsoft has a time slice set at its probably around 50ms so if there are n threads scheduled before yours the delay will be n * ~50ms

In the post above Daniel wrote “More time resolution is only available with multimedia timers or DirectX.” He is right. What I’m speaking about is similar to you listening to music or watching a dvd on your computer. If you do anything that uses the CPU a lot, the music or movie becomes "choppy." That is, indirectly, related to the context switches that I’m talking about. Besides these context switches there are other things like interrupts going on(e.g. moving the mouse).

Anyway, there is always a workaround for coding problems.
Good luck.

BTW: You got me curious. Why do you need such a short delay for?

Context switch:
(this is just a summary, Google around for more details)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/context_switches.asp

Sleep Method:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadclasssleeptopic1.asp



GeneralRe: Thread.Sleep is too slow Pin
eggie525-Jul-03 16:54
eggie525-Jul-03 16:54 
GeneralRe: Thread.Sleep is too slow Pin
LongRange.Shooter25-Jul-03 10:39
LongRange.Shooter25-Jul-03 10:39 
GeneralRe: Thread.Sleep is too slow Pin
Daniel Turini24-Jul-03 11:15
Daniel Turini24-Jul-03 11:15 
GeneralRe: Thread.Sleep is too slow Pin
eggie524-Jul-03 11:33
eggie524-Jul-03 11:33 
GeneralRe: Thread.Sleep is too slow Pin
jparsons24-Jul-03 15:02
jparsons24-Jul-03 15:02 
GeneralCan't Distribute C# Console App. Pin
Dato24-Jul-03 7:27
Dato24-Jul-03 7:27 
GeneralRe: Can't Distribute C# Console App. Pin
Daniel Turini24-Jul-03 8:12
Daniel Turini24-Jul-03 8:12 
GeneralRe: Can't Distribute C# Console App. Pin
Dato24-Jul-03 11:56
Dato24-Jul-03 11:56 
GeneralRe: Can't Distribute C# Console App. Pin
Anonymous24-Jul-03 16:12
Anonymous24-Jul-03 16:12 
GeneralRe: Can't Distribute C# Console App. Pin
Dato25-Jul-03 11:31
Dato25-Jul-03 11:31 
Generaldouble buffering direct draw in a windowed application Pin
pseudonym6724-Jul-03 7:08
pseudonym6724-Jul-03 7:08 
GeneralRe: double buffering direct draw in a windowed application Pin
John Fisher24-Jul-03 16:54
John Fisher24-Jul-03 16:54 
GeneralRe: double buffering direct draw in a windowed application Pin
J. Dunlap24-Jul-03 17:54
J. Dunlap24-Jul-03 17:54 
GeneralRe: double buffering direct draw in a windowed application Pin
pseudonym6724-Jul-03 22:50
pseudonym6724-Jul-03 22:50 
GeneralGlobal Logger instance Pin
albean24-Jul-03 5:33
albean24-Jul-03 5:33 
GeneralRe: Global Logger instance Pin
leppie24-Jul-03 7:15
leppie24-Jul-03 7:15 
GeneralRe: Global Logger instance Pin
Julian Bucknall [MSFT]24-Jul-03 9:00
Julian Bucknall [MSFT]24-Jul-03 9:00 

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.