tags:

views:

384

answers:

3

I am not very familiar with VB.NET so I don't know if this is possible...

Some code I am working on is setting the properties of a very large class. In the setter of each property an event is raised to indicate that the class data has changed. An event handler then serializes the instance of the class to a database.

Obviously I do not want this to happen after each property is set, so I need to either have a delay before saving, or something else.

I am keeping a large list of instances in a cache implementation already, so one option would be to only process the cache every now and then and save all unsaved instances in cache to the database.

So I tried to see if I could derive a class from Application (and override DoEvents), but it is NotInheritable, so no luck there.

Any ideas?

+1  A: 

It isn't entirely clear whether you're talking about the windows message pump, or .NET events. Either way, there are a few common approaches:

  • change the publisher so that it only raises a single event when everything is done; for example, with data-binding to BindingList<T> you can set RaiseListChangedEvents to false while doing a big update, then true afterwards and call the reset method
  • tell the target to disable things like drawing for a duration; for example using a BeginEdit()/ EndEdit() pair of methods
  • if neither is possible: handle the events, but don't do anything immediately; only do something once you believe nothing else is coming; for example by adding a short delay before you do your funky stuff

An example of the last is here: Prevent events from firing multiple times from single action

Marc Gravell
A: 

Add an extra field to your EventArgs class that says "handled". Then, every handler checks this field, and continues only if it is false. Then, once it's done, it sets the field to True.

David Rutten
A: 

There is no "event queue".

Are you asking about this because of a problem you've seen, or because of a concern that you have? If you're asking about a problem, then please edit your question to include details about the problem. If you're asking about a concern, then please edit the question to include some information about what you're concerned about.

John Saunders