Solved

Design advice wanted regarding Timers, Threads and Graphics

Posted on 2003-12-11
3
187 Views
Last Modified: 2013-11-20
Hello,

I'm maintaing an MFC application which has the following characteristics:

 -It  reads information from the Serial port once a second and displays it
 - it has a huge OnPaint method. which displays hundreds of bitmaps.


Performance is understandably very bad.  I'm assuming it's because the current code calls the MFC OnTimer() function to read the data from the serial port, and then calling the huge OnPaint function, which never completes as it is pre-empted.


I had thought about using threads to prevent this from happening and I need some general advice. Would it be better to put the OnPaint function in a separate thread, or to stop using Timers and put the code that reads from the Serial port in a separate thread?  If I do one or both of these things, what specific idiosyncracies does MFC present?  

I'm aware the UI already runs in a separate thread but beyond that I've never done any multiprocessing under Windows.  
0
Comment
Question by:jeslawson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9919846
What does it need to call the OnPaint for?
If only a bit of the client area needs repainting then just repaint that section (check what area has been invalidated).
Maybe keep a DC in memory (needs some work to cope with changing size of window and possible display resolution/colour depth changes) and draw the bitmaps there and BitBlt that to the screen DC during the OnPaint.


In your OnTimer - read the port and invalidate the section of the client area that needs repainting.  Don't try to force it to repaint there and then, let the system do it.

0
 

Author Comment

by:jeslawson
ID: 9949497
I'm already using a Memory DC to implement double buffering but at the minute the OnPaint method redraws all the bitmaps, even the ones that aren't within the client area at the time.  I think this is where the bottleneck is.  Agreed?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 50 total points
ID: 9949586
It is a possibility.  Check which part of the display area is invalidated and just renew/BitBlt that area afresh.

In general be careful with assuming a piece of code is slow.  I once spent ages trying to optimise something that it turned out was only a tiny fraction of the total processing time.  Needless to say it didn't improve performance that much - a re-organise elsewhere resulted in a much more responsive app.  In other words really try to identify the slow code.  (GetTickCount can be useful for a crude go, the profiler tool is much more complex but accurate).
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question