Committed callbacks can be used in various scenarios:
This example shows you how to refresh objects on a client on commits.
When several clients are working on the same objects it is possible that the data will be outdated on a client. You can use the committed-event refresh object on each commit.
When a client commit will trigger a committed event on all clients. In order to refresh the object, register for the committed event. In the commit-event-handler, refresh the object which have been modified.
IEventRegistry events = EventRegistryFactory.ForObjectContainer(container);
events.Committed +=
delegate(object sender, CommitEventArgs args)
{
foreach (LazyObjectReference updated in args.Updated)
{
object obj = updated.GetObject();
args.ObjectContainer().Ext().Refresh(obj, 1);
}
};
Dim events As IEventRegistry = EventRegistryFactory.ForObjectContainer(container) AddHandler events.Committed, AddressOf HandleUpdate
Private Shared Sub HandleUpdate(ByVal sender As Object, ByVal args As CommitEventArgs)
For Each updated As LazyObjectReference In args.Updated
Dim obj As Object = updated.GetObject()
args.ObjectContainer().Ext().Refresh(obj, 1)
Next
End Sub
You can register such a event-handler for each client. The committed event is transferred to each client. Note that this requires a lot of network-traffic to notify all clients and transfer the changes.
When working with committed events you should remember that the listener is called on a separate thread, which needs to be synchronized with the rest of the application.