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 STOP a CPU high expensive method

How to STOP a CPU high expensive method

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 Posts 2 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.
  • D Offline
    D Offline
    doctorpi
    wrote on last edited by
    #1

    Hi guys I've got a method that is really CPU high expensive and I want to stop it when I click the mouse or press a key but , what's the best way to do this without slow the process? I've tried with PeekMessage but it takes a lot of time to stop the process after the key pressed then. Thanks in forwarding DrPi

    B 1 Reply Last reply
    0
    • D doctorpi

      Hi guys I've got a method that is really CPU high expensive and I want to stop it when I click the mouse or press a key but , what's the best way to do this without slow the process? I've tried with PeekMessage but it takes a lot of time to stop the process after the key pressed then. Thanks in forwarding DrPi

      B Offline
      B Offline
      Bob Stanneveld
      wrote on last edited by
      #2

      You can try multithreading. You run your CPU expensive code in the second thread and you can kill it from your main (GUI) thread. The best way to do this is to poll regurlaly for the exit command. See here[^] for more information on this. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

      D 1 Reply Last reply
      0
      • B Bob Stanneveld

        You can try multithreading. You run your CPU expensive code in the second thread and you can kill it from your main (GUI) thread. The best way to do this is to poll regurlaly for the exit command. See here[^] for more information on this. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

        D Offline
        D Offline
        doctorpi
        wrote on last edited by
        #3

        Thanks guy I was suposing that "your solution" is the ONLY correct solution. I'll have to convert my code to a thread. Dr.pi

        B 1 Reply Last reply
        0
        • D doctorpi

          Thanks guy I was suposing that "your solution" is the ONLY correct solution. I'll have to convert my code to a thread. Dr.pi

          B Offline
          B Offline
          Bob Stanneveld
          wrote on last edited by
          #4

          I only know of 2 solutions. This worker-thread solution and the ::PeekMessage() solution. You'll have to choose the one based on your needs. For example if your task is running often or the entire time, you should not even consider the ::PeekMessage() solution. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

          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