IBuildEngine4.RegisterTaskObject Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registers an object with the system that will be disposed of at some specified time in the future.
public:
void RegisterTaskObject(System::Object ^ key, System::Object ^ obj, Microsoft::Build::Framework::RegisteredTaskObjectLifetime lifetime, bool allowEarlyCollection);
public void RegisterTaskObject(object key, object obj, Microsoft.Build.Framework.RegisteredTaskObjectLifetime lifetime, bool allowEarlyCollection);
abstract member RegisterTaskObject : obj * obj * Microsoft.Build.Framework.RegisteredTaskObjectLifetime * bool -> unit
Public Sub RegisterTaskObject (key As Object, obj As Object, lifetime As RegisteredTaskObjectLifetime, allowEarlyCollection As Boolean)
Parameters
- key
- Object
The key used to retrieve the object.
- obj
- Object
The object to be held for later disposal.
- lifetime
- RegisteredTaskObjectLifetime
The lifetime of the object.
- allowEarlyCollection
- Boolean
The object may be disposed earlier than the requested time if MSBuild needs to reclaim memory.
Remarks
This method may be called by tasks which need to maintain state across task invocations, such as to cache data which may be expensive to generate but which is known not to change during the build. It is strongly recommended that allowEarlyCollection be set to true if the object will retain any significant amount of data, as this gives MSBuild the most flexibility to manage limited process memory resources.
In multithreaded builds, in-process tasks share registered objects across thread nodes. The registered object must be safe for concurrent use. Tasks running in different processes, including TaskHost processes, do not share registered objects.
If an object is already registered under an equal key, this call does not replace it. MSBuild does not dispose an object that is not retained by the registration.
The thread on which the object is disposed may be arbitrary - however it is guaranteed not to be disposed while the task is executing, even if allowEarlyCollection is set to true.
If the object implements IDisposable, IDisposable.Dispose will be invoked on the object before discarding it.