SonarLint.VisualStudio.Progress.Controller.Helpers.RunOnFinished C# (CSharp) Method

RunOnFinished() public static method

The onFinishedAction will be called once when the controller will finish by invoking IProgressEvents.Finished.
This code will not cause memory leaks due to event registration
public static RunOnFinished ( this controller, Action onFinishedAction ) : void
controller this Required.
onFinishedAction Action Required. The action that will be invoked with the finished
return void
        public static void RunOnFinished(this IProgressEvents controller, Action<ProgressControllerResult> onFinishedAction)
        {
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }

            if (onFinishedAction == null)
            {
                throw new ArgumentNullException(nameof(onFinishedAction));
            }

            EventHandler<ProgressControllerFinishedEventArgs> onFinished = null;
            onFinished = (o, e) =>
            {
                controller.Finished -= onFinished;
                onFinishedAction.Invoke(e.Result);
            };

            controller.Finished += onFinished;
        }
    }