Workspace close/clear event?

Hi all!
I have a quick question.
What is the better way to capture when a workspace is closed?

Three events are always called.

Nodes cleared, notes cleared, and annotations cleared, so I was thinking of capturing one of those as the event when the workspace will be closed; or is there a better way?

Thanks.

Hi @mircoBianchini ,

Could you supply a little bit of context from where you are getting this information and where you would like to use this for?

I want to capture the event in a viewExtension.
This is where I got that information.

Capturing NodesCleared you will end without any nodes, because the action fires after all the nodes are removed, so the best solution seems to capture MessageLogged that is the first event called when a workspace is closed.

        public void Loaded(ViewLoadedParams viewLoadedParams)
        {
            _viewLoadedParams = viewLoadedParams;
            viewLoadedParams.CurrentWorkspaceModel.NodesCleared += CurrentWorkspaceModel_NodesCleared;
        }

        private void CurrentWorkspaceModel_NodesCleared()
        {
            var dynamoViewModel = _viewLoadedParams.DynamoWindow.DataContext as DynamoViewModel;
            var nodes = dynamoViewModel.CurrentSpace.Nodes.ToList();
            if (nodes.Count == 0) return;
        }
1 Like