MacroFeatureEx{TParams, THandler} Class overload of macro feature allows defining the handler class which will be created for each feature. This provides a simple way to track the macro feature lifecycle (i.e. creation time and deletion time).

public class LifecycleMacroFeatureParams
{
}

public class LifecycleMacroFeatureHandler : IMacroFeatureHandler
{
    public void Init(ISldWorks app, IModelDoc2 model, IFeature feat)
    {
        //feature is created or loaded
    }

    public void Unload()
    {
        //feature is deleted or model is closed
    }
}

[ComVisible(true)]
public class LifecycleMacroFeature : MacroFeatureEx<LifecycleMacroFeatureParams, LifecycleMacroFeatureHandler>
{
    protected override MacroFeatureRebuildResult OnRebuild(LifecycleMacroFeatureHandler handler, LifecycleMacroFeatureParams parameters)
    {
        return MacroFeatureRebuildResult.FromStatus(true);
    }
}

Instance of the handler class will be created and disposed by framework. This approach is useful when macro feature needs to monitor the events of a specific file it resides.