I'm currently working on a part of a winform executable to display tracked events over time, and everything has been working fine on the small tests that I've been working on. However, I noticed a quirk when working on full-scale data sets: After around 5,000 events on a given track, the user can visibly see the tracks being drawn in down the line over the course of a second.
This implies, to me at least, that the DrawLine method is completing a full IO operation for each individual line segment being drawn, which is definitely going to slow the code down to problematic levels in some of my expected cases. Here is the code as it was:
void MyProject::DrawTracks(MyTypes::Track_t ^Track, System::Drawing::Font^ Font)
{
//DisplayPanel is a System::Windows::Form::Panel scaled up to display graphics on
System::Drawing::Graphics ^graphic = DisplayPanel->CreateGraphic();
Pen = gcnew System::Drawing::Pen(Track->Color, 2);
System::Drawing::Point PT, PB;
PointTop = System::Drawing::Point(0, Track->PosY - 3);
PointBot = System::Drawing::Point(0, Track->PosY + 3);
for (unsigned int i = 0; i<Track->nRecs; i++)
{
PointTop.X = CalculateTrackXPos(i, Track);
PointBot.X = PointTop.X;
graphic->DrawLine(Pen, PT, PB);
}
}
My initial impression was that using a batch drawing method, like DrawRectangles, would work, but this had no notable impact on performance. After this, I copied the SuspendDrawing and ResumeDrawing methods submitted by user ng5000 here to pause updates while I drew in the lines, resulting in the following code:
void MyProject::DrawTracks(MyTypes::Track_t ^Track, System::Drawing::Font^ Font)
{
//DisplayPanel is a System::Windows::Form::Panel scaled up to display graphics on
System::Drawing::Graphics ^graphic = DisplayPanel->CreateGraphic();
Pen = gcnew System::Drawing::Pen(Track->Color, 2);
System::Drawing::Point PT, PB;
PointTop = System::Drawing::Point(0, Track->PosY - 3);
PointBot = System::Drawing::Point(0, Track->PosY + 3);
SuspendDrawing(DisplayPanel);
for (unsigned int i = 0; i<Track->nRecs; i++)
{
PointTop.X = CalculateTrackXPos(i, Track);
PointBot.X = PointTop.X;
graphic->DrawLine(Pen, PT, PB);
}
ResumeDrawing(DisplayPanel);
}
Suspend and Resume Drawing both prevented DrawLine from performing any updates to the displayed graphics at all, leaving me curious. How can I draw a series of roughly 11,000 lines using .NET's graphics library without having to perform a costly I/O operation for each one?