How to waste time calling the database multiple times
-
Names changed to protect the innocent....
private void FillGrid()
{
/*Lots of code ommitted...A lengthy function that completely wipes out datatables, re-calls the database, and re-fills the datatables. */
}/*handler called for certain changes to the Case*/
private void Case_SelectionChanged(object sender, EventArgs e)
{
FillGrid();
}private void FillCase(string PatientID)
{
/*(some meaningless code ommitted)*/case.ItemIndex = 0; /*fires the CaseSelectionChanged handler*/
}/*called EVERY time we search...*/
protected void Search()
{
FillCase(PatientID);
case.EditValue = caseNo.Trim(); /*fires the same handler*/
Case_SelectionChanged(new object(), new EventArgs()); /*call the handler directly*/
FillGrid();
}So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really? :doh:
-
Names changed to protect the innocent....
private void FillGrid()
{
/*Lots of code ommitted...A lengthy function that completely wipes out datatables, re-calls the database, and re-fills the datatables. */
}/*handler called for certain changes to the Case*/
private void Case_SelectionChanged(object sender, EventArgs e)
{
FillGrid();
}private void FillCase(string PatientID)
{
/*(some meaningless code ommitted)*/case.ItemIndex = 0; /*fires the CaseSelectionChanged handler*/
}/*called EVERY time we search...*/
protected void Search()
{
FillCase(PatientID);
case.EditValue = caseNo.Trim(); /*fires the same handler*/
Case_SelectionChanged(new object(), new EventArgs()); /*call the handler directly*/
FillGrid();
}So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really? :doh:
That example is not complete, is it? All of the functions you show are private/protected, none is public, and only one gets called by a user interaction. The real fun must be somewhere else. Didn't you see a function like:
private void Button1_Click(object sender, EventArgs e)
{
//remove the previous selection
FillCase("");
Search();
Case_SelectionChanged(new object(), new EventArgs());
FillGrid();
//get fresh data and show them
FillCase("some value");
Search();
Case_SelectionChanged(new object(), new EventArgs());
FillGrid();
//make sure that it is really the data of the selected case which are shown
... and some more lines of code
} -
Names changed to protect the innocent....
private void FillGrid()
{
/*Lots of code ommitted...A lengthy function that completely wipes out datatables, re-calls the database, and re-fills the datatables. */
}/*handler called for certain changes to the Case*/
private void Case_SelectionChanged(object sender, EventArgs e)
{
FillGrid();
}private void FillCase(string PatientID)
{
/*(some meaningless code ommitted)*/case.ItemIndex = 0; /*fires the CaseSelectionChanged handler*/
}/*called EVERY time we search...*/
protected void Search()
{
FillCase(PatientID);
case.EditValue = caseNo.Trim(); /*fires the same handler*/
Case_SelectionChanged(new object(), new EventArgs()); /*call the handler directly*/
FillGrid();
}So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really? :doh:
-
He just wanted to be on the safe side and assured that the grid is filled, no matter what happens :)
And from the clouds a mighty voice spoke:
"Smile and be happy, for it could come worse!"And I smiled and was happy
And it came worse.From what I can see the grid won't actually be filled if the FillGrid throws an Exception. Unless there is a deleted try catch block there that recursively calls the FillGrid Method again in its catch block... :rolleyes:
It's an OO world.
public class Naerling : Lazy<Person>{}
-
Names changed to protect the innocent....
private void FillGrid()
{
/*Lots of code ommitted...A lengthy function that completely wipes out datatables, re-calls the database, and re-fills the datatables. */
}/*handler called for certain changes to the Case*/
private void Case_SelectionChanged(object sender, EventArgs e)
{
FillGrid();
}private void FillCase(string PatientID)
{
/*(some meaningless code ommitted)*/case.ItemIndex = 0; /*fires the CaseSelectionChanged handler*/
}/*called EVERY time we search...*/
protected void Search()
{
FillCase(PatientID);
case.EditValue = caseNo.Trim(); /*fires the same handler*/
Case_SelectionChanged(new object(), new EventArgs()); /*call the handler directly*/
FillGrid();
}So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really? :doh:
Did you got the guy fired, cause of such guys the software can't cope up even with hardware advancements. Even with a quad core machines and GBs of RAM we still have the same performance issues we used to have in the days of Pentium I and a few MB of RAM.