There aren't any process framework event interfaces that you can hook up to, unfortunately. I wonder if you can listen for the Start Editing event on the Editor object, then query the Px App / Session Mgr extension for the current session.
Let me know if you have some other creative ideas we can toss around.
Thanks for the suggestion @Stetson.
In the end my approach (simplified a bit) is:
* Track the current session id (if any).
* Use IActiveViewEvents.ContentsChanged
* Use ICommand.Enabled
To detect opening of session:
I use the Enabled property of my command used to launch the form. In the Enabled handler I check if the form is opened, if my stored session id is set to 0 and if there is a session manager available. If so, I get the current session id and compare it to my stored. If it differs, a session has just been opened and store the new session id and dismiss my form.
This reliably tracks session opening without slowing down the Enabled handler much, if anything.
To detect closing of session:
I listen to the IActiveViewEvents.ContentsChanged event and check if there is a current session and the id, and compare it to my stored session id. If they differ, the session has been closed.
As ContentsChanged gets called after the session is closed, this reliably tracks session closing.
Detecting version changes outside of Session Manager:
By also tracking the current selection with IActiveViewEvents.SelectionChanged and also using ContentsChanged, I can also detect version changes outside of Session Manager, as everything is always deselected when a version change occurs, before ContentsChanged is called. The only drawback to this is when the user deselects everything and moves/zooms the map which triggers ContentsChanged. This specific use case will lead to my form being dismissed as I have no way of properly detecting if it was a version change or not. Better safe than sorry. This is only done if there is no current or previous session session or no session manager available.
Hope this can be of use for someone else. Or if someone sees a big downside to this, please leave a reply!
The only thing I can think of off-hand is that the ICommand.Enabled is called at least every second. I'm wondering if there is another event that you can use to set a boolean which the command can simply read rather than execute logic.
Yeah, ICommand.Enabled gets called a lot, so my logic will at best only check one or two internal variables, at worst get the current session id every time. If the form is closed or a session id has already been retrieved, no work needs to be done.
The worst-case scenario is when a session manager is present but no session is open, ie after a session has been opened, then closed, and no new session has been opened. I would think that if you use Session Manager, you tend to do it all the time, so the worst-case scenario would not be an issue. And depending on how fast it is to get the current session id, it may even be a non-issue?