Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to do sleep in microsecond

How to do sleep in microsecond

Scheduled Pinned Locked Moved C#
helptutorial
10 Posts 8 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kobi10i10
    wrote on last edited by
    #1

    Hi Please help me!!!

    J S D K E 5 Replies Last reply
    0
    • K kobi10i10

      Hi Please help me!!!

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      There is no way from the .NET framework to make a thread sleep for less than a millisecond. You can call Thread.Sleep(0) which will simply cause the process to switch contexts and let another thread run for a moment before returning and processing the current thread.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: And in this corner, the Party of Allah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      1 Reply Last reply
      0
      • K kobi10i10

        Hi Please help me!!!

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        Maybe the StopWatch class can help you.

        StopWatch watch = StopWatch.StartNew();
        while (watch.ElapsedTicks < someValue)
        {
        }

        somevalue has to be computed from Stopwatch.Frequency to reflect the wanted amount of microseconds. Should be some easy math but I'm too lazy and also want to leave some coding for you :) -- modified at 16:26 Monday 14th August, 2006 Just an annotation: This way your thread doesn't really sleep but actively waits for time to go by, so this isn't really good practice and shouldn't be used often.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        1 Reply Last reply
        0
        • K kobi10i10

          Hi Please help me!!!

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          It can't be done. The Windows platform doesn't have programmable access to any hardware timers with that kind of resolution.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          E 1 Reply Last reply
          0
          • K kobi10i10

            Hi Please help me!!!

            K Offline
            K Offline
            kalyanPaladugu
            wrote on last edited by
            #5

            Thread.Sleep(100). This worked for me before

            E D 2 Replies Last reply
            0
            • K kalyanPaladugu

              Thread.Sleep(100). This worked for me before

              E Offline
              E Offline
              Ennis Ray Lynch Jr
              wrote on last edited by
              #6

              A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

              1 Reply Last reply
              0
              • K kalyanPaladugu

                Thread.Sleep(100). This worked for me before

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                1 millisecond = 1000 microseconds...

                Dave Kreskowiak Microsoft MVP - Visual Basic

                1 Reply Last reply
                0
                • K kobi10i10

                  Hi Please help me!!!

                  E Offline
                  E Offline
                  eggie5
                  wrote on last edited by
                  #8

                  Look at the FrameworkTimer in the DirectX SDK!

                  /\ |_ E X E GG

                  D 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    It can't be done. The Windows platform doesn't have programmable access to any hardware timers with that kind of resolution.

                    Dave Kreskowiak Microsoft MVP - Visual Basic

                    E Offline
                    E Offline
                    Ed Poore
                    wrote on last edited by
                    #9

                    I was wondering when someone would realise this :rolleyes:


                    Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

                    1 Reply Last reply
                    0
                    • E eggie5

                      Look at the FrameworkTimer in the DirectX SDK!

                      /\ |_ E X E GG

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      Althought the QueryPerformanceCounter function does have a resolution of 1 microsecond, you cannot sleep a process that accurately. The best your going to do is 1 millisecond, and even then, the resolution can vary by 10-15 milliseconds due to Windows being a shared system.

                      Dave Kreskowiak Microsoft MVP - Visual Basic

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups