Click or drag to resize
Ab4d.SharpEngine logo

ResourceTracker Class

ResourceTracker collects classes that implement ComponentBase and can report all created objects. Objects are collected with WeakReference. Resource tracker is also used to get the next object id by calling its GetNextId(IComponentBase) method.
Inheritance Hierarchy
SystemObject
  Ab4d.SharpEngine.UtilitiesResourceTracker

Namespace: Ab4d.SharpEngine.Utilities
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 1.0.8740+deb2991acfe86a95cca780cd4f82bcae2805c1a5
Syntax
C#
public static class ResourceTracker

The ResourceTracker type exposes the following members.

Properties
 NameDescription
Public propertyStatic memberIsTrackingResources Gets a boolean that specifies if tracking resources is enabled.
Top
Methods
 NameDescription
Public methodStatic memberAddResource Add an object to the list of tracked resources.
Public methodStatic memberDumpTrackedResources Writes formatted string with tracked resources with the System.Diagnostics.Debug.WriteLine.
Public methodStatic memberGetById 
Public methodStatic memberGetNextId Get next Id as a long value that is unique for this application. This method is thread safe and can be called from any thread. When ResourceTracking is enabled then the creation of componentBase object will be recorded and the object's lifecycle will be tracked by this ResourceTracker.
Public methodStatic memberGetTrackedResources Gets a list of ComponentBase objects that were tracked while tracking was enabled and are still alive (garbage collector did not disposed them yet).
Public methodStatic memberGetTrackedResourcesReport Gets a formatted string with tracked resources.
Public methodStatic memberStartTrackingResources Starts tracking of resources.
Public methodStatic memberStopTrackingResources Stop tracking resources.
Top
Remarks

ResourceTracker collects classes that implement ComponentBase and can report all created objects.

To enable components tracking call the StartTrackingResources method.

To track all resources this method must be called before any other object is created (for example before InitializeComponent in the application's main window).

When resource tracking is enabled, then all the components are stored in a WeakReference list. It is possible to get collection of all resources that were collected - their ids, object type, name, etc.

After the resources have been tracked, it is possible to get tracked resources by GetTrackedResources, GetTrackedResourcesReport(Boolean, Boolean, Boolean) or display the tracked resources in Visual Studio's Immediate Window with DumpTrackedResources(Boolean, Boolean).

It is possible to stop tracking resources with StopTrackingResources.

See Also