NotifyDataChangedGetEventQueue Method | 
Namespace: Demo3D.Net
public static NotifyDataChangedEventQueue GetEventQueue( this INotifyDataChanged notify )
Given an INotifyDataChanged interface, this will return a NotifyDataChangedEventQueue that has subscribed to the INotifyDataChanged.DataChanged event. The NotifyDataChangedEventQueue collects data changed events and delivers them to the caller on request.
This method facilitates code that can use a construct, such as a while loop, to wait for and respond to data changes.
For message streams (such as IPacketIOService), it's more efficient simply to loop calling IPacketIOService.ReadAsync(). GetEventQueue is mainly aimed at services that implement INotifyDataChanged but have no blocking Read(Async) method (or similar).
// Reacts to data changing. // For services such as IMemoryService or ITagService that don't have a Read method (or similar). // GetEventQueue returns an object that will watch for INotifyDataChanged.DataChanged events // and return each one as they occur. public async Task ReactToDataChanging(bool sync, INotifyDataChanged service) { using (var notifier = service.GetEventQueue()) { for (;;) { foreach (var data in await notifier.ReadEventsAsync(sync).ConfigureAwait(false)) { Logger.Log("Data changed"); } } } } // Reacts to data changing. // For services such as IPacketIOService that do have a Read method, it's simpler and cheaper // just to Read the data directly. The effect is the same. public async Task ReactToDataChanging(IPacketIOService service) { for (;;) { var data = await service.ReadAsync(length: -1); // -1 means read all the available data Logger.Log("Data changed"); } }