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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CStatic drawing interrupted... Worker, UI Threads????

CStatic drawing interrupted... Worker, UI Threads????

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdesignc++questionannouncement
5 Posts 3 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.
  • G Offline
    G Offline
    Greg Ellis
    wrote on last edited by
    #1

    Hey Guys, I have an MFC CStatic derived class that has a public member function Draw();. Draw uses GDI to draw stuff to the CStatic window. I call this Draw method from a multimedia timer (timeSetEvent) to continually update the display. My problems is that When my main app is doing a lot of work the drawing is sometimes interrupted when I load files. So I put the lengthy process of loading files in a worker thread, but the drawing is still "jerky" when loading a file. Is there anything else I can do to ensure that my CStatic is always drawing? Is this something I need a user interface thread for? Thanks, Greg

    M M 2 Replies Last reply
    0
    • G Greg Ellis

      Hey Guys, I have an MFC CStatic derived class that has a public member function Draw();. Draw uses GDI to draw stuff to the CStatic window. I call this Draw method from a multimedia timer (timeSetEvent) to continually update the display. My problems is that When my main app is doing a lot of work the drawing is sometimes interrupted when I load files. So I put the lengthy process of loading files in a worker thread, but the drawing is still "jerky" when loading a file. Is there anything else I can do to ensure that my CStatic is always drawing? Is this something I need a user interface thread for? Thanks, Greg

      M Offline
      M Offline
      Matthew Faithfull
      wrote on last edited by
      #2

      I'm not certain what you're trying to achieve here as genuinely constant redrawing would preclude you doing anything else anyway but you may have run up against a perenial problem with the MFC architecture. Essentailly anything done to the user interface is done on the main thread even if you call it from a worker thread. I would definitely suggest doing the file loading on a worker thread before getting into the absolute minefield of multiple user interface threads.

      Nothing is exactly what it seems but everything with seems can be unpicked.

      G 1 Reply Last reply
      0
      • M Matthew Faithfull

        I'm not certain what you're trying to achieve here as genuinely constant redrawing would preclude you doing anything else anyway but you may have run up against a perenial problem with the MFC architecture. Essentailly anything done to the user interface is done on the main thread even if you call it from a worker thread. I would definitely suggest doing the file loading on a worker thread before getting into the absolute minefield of multiple user interface threads.

        Nothing is exactly what it seems but everything with seems can be unpicked.

        G Offline
        G Offline
        Greg Ellis
        wrote on last edited by
        #3

        Basically I have two music files playing (video and/or audio) I am showing a scrolling waveform as the song is playing in realtime (using GDI). I need this waveform to always scroll. When loading a file into the second player while the first player is playing the scrolling waveform is being interrupted. I just need that waveform to always be scrolling. So MFC always draws from the main thread no matter what? That's no good for me. Is my only option UI threads?

        M 1 Reply Last reply
        0
        • G Greg Ellis

          Basically I have two music files playing (video and/or audio) I am showing a scrolling waveform as the song is playing in realtime (using GDI). I need this waveform to always scroll. When loading a file into the second player while the first player is playing the scrolling waveform is being interrupted. I just need that waveform to always be scrolling. So MFC always draws from the main thread no matter what? That's no good for me. Is my only option UI threads?

          M Offline
          M Offline
          Matthew Faithfull
          wrote on last edited by
          #4

          If you're doing that sort of thing and you want it really smooth I'd consider DirectX/OpenGL or perhaps just doing everything except the drawing in lower priority background threads and relying on having enough hardware under the bonnet to keep up. Double buffering may be your friend aswell when it comes to getting smooth display updates. i.e. draw it all to an off screen Bitmap and then blit that to the screen in one go. With a bit of manipulation perhaps you could do the scrolling in the bitmap memory aswell without having to redraw the old parts of the waveform. It's a while since I did much PC based MFC but I certainly wouldn't have recommended it for the sort of app your describing when I did. Having said that there may be other issues causing your problems. Are you using a cyclic or fixed buffer that doesn't do any heap allocation while in use to store your waveform? If not you're going to get horrible performance glitches from the memory allocator for example. Are you maxing out your current hardware? If you check the performance monitor while your app is the only one running and it's flat out at 100% then either you've got some ineffecient code or you're trying to push your hardware beyond what it can achieve. Ultimately all such jolts and flickers are down to something being blocked either by synchronisation or a bandwidth limit somewhere. Unless something is resource stealing. In that regard watch out for the Quicktime tray icon app if you use DirectX it can steal the graphics card from you every few seconds and cause horrible jitter.

          Nothing is exactly what it seems but everything with seems can be unpicked.

          1 Reply Last reply
          0
          • G Greg Ellis

            Hey Guys, I have an MFC CStatic derived class that has a public member function Draw();. Draw uses GDI to draw stuff to the CStatic window. I call this Draw method from a multimedia timer (timeSetEvent) to continually update the display. My problems is that When my main app is doing a lot of work the drawing is sometimes interrupted when I load files. So I put the lengthy process of loading files in a worker thread, but the drawing is still "jerky" when loading a file. Is there anything else I can do to ensure that my CStatic is always drawing? Is this something I need a user interface thread for? Thanks, Greg

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            I don't agree that all drawing is done on one thread. Through WM_PAINT maybe, but if you're using GDI to draw from another thread then it's drawing on that thread. I do video rendering and it's definitely not on one UI thread :) *edit* BTW, I've personally never used multiple UI threads - I meant multiple worker threads doing GDI drawing. Try calling GDIFlush() when you're done drawing each time. Also remember GDI is not thread safe - It's up to you to sync drawing from other threads with drawing that may occur in response to WM_PAINT on the UI thread. Mark -- modified at 13:15 Wednesday 4th July, 2007

            Mark Salsbery Microsoft MVP - Visual C++ "Go that way, really fast. If something gets in your way, turn."

            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