Avoiding infinite loop on datarow changes

  • Thread starter Thread starter Whuggy
  • Start date Start date
W

Whuggy

Hi.

I have a DataTable class that interfaces with the QuickBooks SDK. The class
subscribes to its own RowChanged event and in the handler method, it does a
select and in case of a DataRowAction.Change, another method is called to
(a) put the updated row values in QuickBooks, and (b) get a field that
QuickBooks automatically updates back to the updated DataRow.

The problem happens in that step (b). What is happening is the updating
function fires the RowChanged event and in turn calling itself along the
way. I wonder what is the correct technique for this scenario.
 
Hi Whuggy,

I would put a flag at class level.
Within rowchanged:
if (!flag)
{
flag = true;
try
{
do processing
}
finally
{
flag = false;
}

}

HTH,
 
Back
Top