Visual C# Developer Center >
Visual C# Forums
>
Visual C# General
>
Please help me optimizing my app.
Please help me optimizing my app.
- hi, everybody
I'm recently working on a windows form application for a automation test system.
The app imports a ActiveX control for automation tests, which provides some events like "BeforeTestBegin","AfterTestDone"...
On the form, there is a dataGridView. I need to add a new row of measurements to dataGridView in "AfterTestDone" event handler.
Now my problem is that because the tests are running very fast, which is pretty much what we expected. Then after each TestDone, adding a new dataviewgrid row takes more time(compare to each test run), which low down the tests running speed.
I was thinking about starting a new thread to keep tests running other than waiting for adding a new row finished. But I failed because It starts a new thread after each TestDone which causes conflict with the current row number.
Here is my original snippet:
private void axTestExecSL1_AfterTestDone(object sender, AxHPTestExecSL.DTestExecSLEvents_AfterTestDoneEvent e)
{
string[] row = new string[5];
row[0] = UutPosId;
row[1] = TestName;
row[2] = LowLimit;
row[3] = HighLimit;
row[4] = LastMeasuredValue;
dataGridView.Rows.Add(row);
}
The measurement updates after each test done, which means If I create a new thread I should pass the measurements to the new thread. Can someone help me with that? I have no idea how to optimize the speed. Using thread? or other options?
Kind Regards,
Answers
- Use virtual mode on the DGV. Since the DGV does nothing for rows outside what's being displayed, using virtual mode will result in there being zero impact after the first N rows.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.virtualmode.aspx- Marked As Answer byAbe119 Wednesday, November 04, 2009 2:33 PM
All Replies
Assuming that updating the DGV is slowing things down, you can allow the AfterTestDone event to complete using a timer. Try this before you implement threading.
Timer tmr = new Timer(); private void Form1_Load(object sender, EventArgs e) { tmr.Interval = 1; //Minimun, but not actually 1 ms. tmr.Tick += tmr_Tick; } private void axTestExecSL1_AfterTestDone(object sender, AxHPTestExecSL.DTestExecSLEvents_AfterTestDoneEvent e) { string[] row = new string[5]; row[0] = UutPosId; row[1] = TestName; row[2] = LowLimit; row[3] = HighLimit; row[4] = LastMeasuredValue; tmr.Tag = row; tmr.Start(); } void tmr_Tick(object sender, EventArgs e) { tmr.Stop(); string[] row = (string[])tmr.Tag; dataGridView.Rows.Add(row); }
- Use virtual mode on the DGV. Since the DGV does nothing for rows outside what's being displayed, using virtual mode will result in there being zero impact after the first N rows.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.virtualmode.aspx- Marked As Answer byAbe119 Wednesday, November 04, 2009 2:33 PM
- Try it with the tmr_Stop(); statement. Tergiver's suggestion is excellent.
- Thanks guys!
Appreciated!


