Resource |
public static class ResourceTracker
The ResourceTracker type exposes the following members.
Name | Description | |
---|---|---|
IsTrackingResources | Gets a boolean that specifies if tracking resources is enabled. |
Name | Description | |
---|---|---|
AddResource | Add an object to the list of tracked resources. | |
CleanTrackedResources | Cleans the dead tracked resources | |
DumpTrackedResources | Writes formatted string with tracked resources with the System.Diagnostics.Debug.WriteLine. | |
GetById | ||
GetNextId | 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. | |
GetTrackedResources | Gets a list of ComponentBase objects that were tracked while tracking was enabled and are still alive (garbage collector did not disposed them yet). | |
GetTrackedResourcesReport | Gets a formatted string with tracked resources. | |
StartTrackingResources | Starts tracking of resources. | |
StopTrackingResources | Stop tracking resources. |
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.