Click or drag to resize

NotifyDataChangedGetDataChangedNotifier Method

Subscribes to data changed events and returns a DataChangedNotifier.

Namespace:  Demo3D.Net
Assembly:  Demo3D.IO (in Demo3D.IO.dll) Version: 10.0.0.0 (10.0.0.0)
Syntax
C#
public static NotifyDataChangedDataChangedNotifier GetDataChangedNotifier(
	this INotifyDataChanged notify
)

Parameters

notify
Type: Demo3D.NetINotifyDataChanged
The INotifyDataChanged interface.

Return Value

Type: NotifyDataChangedDataChangedNotifier
A DataChangedNotifier object that will store and forward data changed events.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type INotifyDataChanged. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks

Given an INotifyDataChanged interface, this will return a DataChangedNotifier that has subscribed to the INotifyDataChanged.DataChanged event. The DataChangedNotifier 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(). GetDataChangedNotifier is mainly aimed at services that implement INotifyDataChanged but have no blocking Read(Async) method (or similar).

Examples
C#
// Reacts to data changing.
// For services such as IMemoryService or ITagService that don't have a Read method (or similar).
// GetDataChangedNotifier returns an object that will watch for INotifyDataChanged.DataChanged events
// and return each one as they occur.
public async void ReactToDataChanging(INotifyDataChanged service) {
    using (var notifier = service.GetDataChangedNotifier()) {
        for (;;) {
            foreach (var data in await notifier.WhenDataChangedAsync()) {
                Logger.Log("Data changed at time " + data.Time);
            }
        }
    }
}

// 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 void ReactToDataChanging(IPacketIOService service) {
    for (;;) {
        var data = await service.ReadAsync();
        Logger.Log("Data changed at time " + DateTime.Now);
    }
}
See Also