Since your Draw method makes sure that while the background thread is busy, a draw doesn't happen on the bitmap - you don't need to keep creating a new bitmap. In fact, looking at the size of the bitmap you're creating, I bet a lot of your 5-10 second draw is taken up by simply creating that bitmap object. This is of course making the assumption that your bitmap size isn't constantly changing - if that is the case, then ignore this post - if the bitmap size is (fairly) constant, then keep reading.
class SomeForm : Form
{
private Bitmap _theImage;
private bool _working = false;
void worker_DoWork(object sender, DoWorkEventArgs e)
{
// make sure the image is initialized (may as well do it on the background thread).
if (_theImage == null)
{
int width = (int)Math.Round(Width * fDPIX);
int height = LogHeightPixels;
_theImage = new Bitmap(width, height/*, System.Drawing.Imaging.PixelFormat.Gdi/*.Format32bppArgb*/);
}
// note, you may need to clear the bitmap in this method call.
// it all depends on what the draw log method is doing.
DrawLogToBitmap(_theImage);
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
_working = false;
Refresh();
}
public override void Draw(Graphics gfx, Rectangle rect)
{
gfx.ScaleTransform(zoom, zoom);
// Update the bitmap (only as needed)
if (bDirty)
{
// I'm assuming this method starts the worker thread - if so:
\_working = true;
UpdateBitmap(gfx);
}
if (\_working || worker.IsBusy)
{
gfx.DrawString("Updating Bitmap, please wait!", this.Font, Brushes.Black, new PointF(0, 0));
return;
}
RectangleF rcSource = new RectangleF(-horizontalOffset, -verticalOffset, ClientRectangle.Width/zoom, ClientRectangle.Height/zoom);
RectangleF rcDest = new RectangleF(ClientRectangle.Location.X, ClientRectangle.Location.Y, ClientRectangle.Size.Width/zoom, ClientRectangle.Size.Height/zoom);
try
{
gfx.DrawImage(\_theImage, rcDest, rcSource, GraphicsUnit.Pixel);
}
catch (Exception exc)
{
gfx.DrawString(exc.Message, Font, Brushes.Black, new PointF(0,0));
}
etc....
}
}
I may have missed something (I've been up for FAR too long, and can't sleep for some reason), but that's the gist of it. You'll probably want to do a few more checks to make sure the bitmap isn't being accessed from multiple threads at the same