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 / C++ / MFC
  4. How to delay about 1/20 milisecond ?

How to delay about 1/20 milisecond ?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 5 Posters 0 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.
  • Q Offline
    Q Offline
    quangpk
    wrote on last edited by
    #1

    I want to create a time delay about 1/20 milisecond.

    K B N A 4 Replies Last reply
    0
    • Q quangpk

      I want to create a time delay about 1/20 milisecond.

      K Offline
      K Offline
      kakan
      wrote on last edited by
      #2

      You can use QueryPerformanceCounter().

      1 Reply Last reply
      0
      • Q quangpk

        I want to create a time delay about 1/20 milisecond.

        B Offline
        B Offline
        babuprasath
        wrote on last edited by
        #3

        hai do u know assmbly language. if u know 8086 assm lan Easily you can create a time delay

        1 Reply Last reply
        0
        • Q quangpk

          I want to create a time delay about 1/20 milisecond.

          N Offline
          N Offline
          nde_plume
          wrote on last edited by
          #4

          You probably can't reliably without going to extrodinary means. This is because Windows is not a Real time operating system, and at any stage your process could be preempted. However, the closest you can get is by calling ::Sleep(20) In reality this will sleep more than twenty milliseconds quite often, because it relinquishes your timeslice in the process scheduler, but it is the best you can do without doing something really hard. Despite what my mis-spelling co-poster tells you, going to assembly language will not offer you any benefit over the above, because it is no less subject to pre-emption than anything else. He/she might argue that you do not relinquish your timeslice as above, however the same can be accomplished in C++ too. For example: class Timer { public: Timer(); void wait(DWORD ms); private: static int cyclesPerMs; // Number of loop iterations per millisecond }; int Timer::cyclesPerMs = -1; Timer::Timer() { const CALIBRATION_TICKS = 100000; if(cyclesPerMs == -1) { // Calibrate timer clock_t start = clock(); for(int i=0; i

          1 Reply Last reply
          0
          • Q quangpk

            I want to create a time delay about 1/20 milisecond.

            A Offline
            A Offline
            Alexander M
            wrote on last edited by
            #5

            What do you need the delay for? Don't try it, just do it! ;-)

            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