Issue 674: Work out a way for an interactive tool to know Skyline is closing or has closed

Assigned To:Brendan MacLean
Opened:2019-08-20 by Brendan MacLean
Changed:2019-09-07 by Brendan MacLean
2019-08-20 Brendan MacLean
Title»Work out a way for an interactive tool to know Skyline is closing or has closed
Assigned ToGuest»Brendan MacLean
Notify»nils hoffmann
Development on the interactive tool LipidCreator reported they can't tell when Skyline is closing and hence end up leaving LipidCreator open when it is no longer useful. They have suggested we add a new OnClosing() event to IDocumentChangeReceiver. Though, I wonder if it might be made possible to tell in response to the existing DocumentChanged and SelectionChanged events combined with the fact that this series of events will eventually close the named pipe Skyline is using to communicate. Do named pipes themselves have events?

2019-09-07 Brendan MacLean
Nils Hoffman reported the following solution below in email. I think something like this may be the best direction rather than relying on Skyline itself to send an event before closing. But, it would also be nice if the implementation could be wrapped as an event in the SkylineTool library.

Dear Brendan,
please find part (sans custom event and listener implementation) of our current workaround for the Skyline pipe connection checking below.

The "pipe" is what we receive from Skyline on startup. We basically construct a new read-only pipe stream which we poll regularly. Not sure whether this could be
done more elegantly with a notification mechanism, but this ensures, that we terminate in any case if Skyline is no longer there or doesn't respond. Comments welcome :-)!

                 skylineToolClient = new SkylineToolClient(pipe, "LipidCreator");
                skylineToolClient.DocumentChanged += OnDocumentChanged;
                skylineToolClient.SelectionChanged += OnSelectionChanged;
                log.Info("LipidCreator is connected to Skyline file: '" + skylineToolClient.GetDocumentPath()+"'");
                Task.Factory.StartNew(() =>
                    var client = new NamedPipeClientStream(@".", pipe, PipeDirection.In);
                    log.Info("Opening connection to Skyline through pipe " + pipe);
                    log.Info("Connected to Skyline through pipe " + pipe);
                    while (client.NumberOfServerInstances>0)
                        log.Debug("Checking Skyline pipe connection!");
                        var nServers = client.NumberOfServerInstances;
                        log.Debug(nServers+" servers available on other end of pipe!");

                    if (client.NumberOfServerInstances == 0)
                        OnSkylineConnectionClosed(new EventArgs());
                        log.Info("Skyline connection was terminated from the other side! Bye bye!");

Best wishes,