Menu

#27 Implemented double buffering and threaded drawing

open
nobody
None
5
2012-09-19
2007-05-14
ReinynB
No

A DoDrawingThread method was added and it is called from OnPaint. The method runs continously in a seperate thread waiting for drawingEvent to be set. Calling drawingEvent.Set() will start the waiting thread drawing into the buffer. When the drawing is completed the buffer is rendered to the screen. The thread runs with low priority so other tasks are not impacted by zedGraph rendering.

This needs further refinement, it will not behave well if the master pane is destroyed and re-created while the control is active.

I had to overload OnPaintBackground and the base class method is only called if the background will actually be rendered.

I also had to take out all the locks in OnPaint, the drawing routing in DoDrawingThread is locked.

Discussion

  • ReinynB

    ReinynB - 2007-06-06

    Logged In: YES
    user_id=1641656
    Originator: YES

    I found a problem where getting the panelist and accessing it from a different thread then that which hosted the zedgraph control could cause a problem. I made a wrapper class for the PaneList so that it could be locked approriately.
    File Added: PaneList.cs

     
  • ReinynB

    ReinynB - 2007-06-06

    panelist needed to be thread safe

     
  • ReinynB

    ReinynB - 2007-06-06

    Logged In: YES
    user_id=1641656
    Originator: YES

    Added a event to clean up the drawing thread when the control is being destroyed
    File Added: ZedGraphControl.cs

     
  • ReinynB

    ReinynB - 2007-06-06

    ZedGraphControl 5.0.8 modified source, now cleans up drawing thread

     
  • John Champion

    John Champion - 2007-08-10

    Logged In: YES
    user_id=957634
    Originator: NO

    Hi,
    Thanks for the contribution. I'm looking into this, but have you had any more thoughts on the MasterPane destroy/create issue?
    John

     
  • ReinynB

    ReinynB - 2007-08-13

    Logged In: YES
    user_id=1641656
    Originator: YES

    Hello John,

    I believe what needs to happen is that graphics buffer and the drawing thread need to be cleaned up when the MasterPane is destroyed. The MasterPane destructor will probably have to wait for the drawing thread to exit. This may not be as much of a problem as I thought at first since I subsequently added the clean up code for the drawing event. Basically it needs further testing to check for any problems since the way I am using the control is to initially create a MasterPane and then use that pane for the lifetime of the control. There may be a problem if the MasterPane is changed while the drawing thread is running.

     

Log in to post a comment.