Skip to content

Keeping in Control of Events

Brian Takita
Authors:Brian Takita
Posted on:September 23, 2004

At work, I'm having an issue with losing control over events in my code. One big issue I'm having is recursion in the `DataRow.RowChanged` event.

Originally posted on geekswithblogs.net

At work, I'm having an issue with losing control over events in my code. One big issue I'm having is recursion inthe DataRow.RowChanged event.

In this case, I'm trying to update the database, during every whenever e.Action == DataRowAction.Changed. This alsomeans having a call to DataRow.AcceptChanges() which raises another DataRowAction.Changed. I also have instanceswhen e.Action == DataRowAction.Changed but DataRow.RowState == DataRowState.Unchanged.

Some thoughts I came up with to try to combat this madness is to...

  • Lock the object that fired the event
  • Check if the object state matches the event state. If not, throw an exception.
  • Implement an event counter.
  • Unit test the event count.

What kinds of things do all of you do to keep events under control?