Information Technology Reference
In-Depth Information
have to implement. In this case, you have to implement two interfaces:
INotifyPropertyChanged and INotifyPropertyChanging. These are both
very simple interfaces; each supports one event. The event argument
for both of these events simply contains the name of the property that's
being updated. You can use the Expression API to create extensions that
remove the dependency on the property name. The extensions will use the
Expression API to parse the name of the property and will execute the
expression algorithm to change the property value.
The late binding implementation for these properties is very simple. Your
data classes need to declare support for both interfaces. Every property
that can be changed needs some extra code to raise those events. Here's a
class that displays the amount of memory used by the current program.
It automatically updates itself every 3 seconds. By supporting the
INotifyPropertyChanged and INotifyPropertyChanging interfaces, an
object of this type can be added to your window class, and you can see
your runtime memory usage.
public class MemoryMonitor : INotifyPropertyChanged ,
INotifyPropertyChanging
{
System.Threading. Timer updater;
public MemoryMonitor()
{
updater = new System.Threading. Timer ((_) =>
timerCallback(_),
null , 0 , 5000 );
}
private void timerCallback( object unused)
{
UsedMemory = GC .GetTotalMemory( false );
}
public long UsedMemory
{
get { return mem; }
private set
{
 
Search WWH ::




Custom Search