SessionEvents in Windows

Posted by Roger Blanchard on 15-Jan-2018 11:04

Does anyone know if we can use the SessionEvents in windows so I can gracefully shutdown myapp. I have no UI just a process spinning that is used for replication. If the user logs off or restarts the PC I want to subscribe to SessionEnding event so I can do what I need to do.

I have tried the following but while it compiles just fine the event is not being called.

SystemEvents:SessionEnding:Subscribe(OnSessionEnding).

METHOD PUBLIC VOID OnSessionEnding (sender AS System.Object,
                                       e AS Microsoft.Win32.SessionEndingEventArgs):
                                        
  
  // shutdown app


    END METHOD.

Posted by Matt Gilarde on 16-Jan-2018 07:11

Do you have a WAIT-FOR? Without a WAIT-FOR the message pump won't run. You may need to follow another note in the documentation, which talks about services but would also apply to an OpenEdge client which doesn't display a UI. The example it refers to starts the message pump with Application.Run(). In an AVM that would be done with WAIT-FOR Application:Run().

[quote]In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the SystemEvents class.[/quote]

All Replies

Posted by Matt Gilarde on 16-Jan-2018 06:47

I haven't written code which uses the SessionEnding event but the documentation for it (https://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionending(v=vs.110).aspx) states:

[quote]This event is only raised if the message pump is running.[/quote]

Which client are you trying to use this with? If you're using the character client or an appserver agent there is no message pump so the event won't fire.

Posted by Roger Blanchard on 16-Jan-2018 06:58

GUI client (prowin32.exe, prowin.exe, prowc.exe)

Posted by Matt Gilarde on 16-Jan-2018 07:11

Do you have a WAIT-FOR? Without a WAIT-FOR the message pump won't run. You may need to follow another note in the documentation, which talks about services but would also apply to an OpenEdge client which doesn't display a UI. The example it refers to starts the message pump with Application.Run(). In an AVM that would be done with WAIT-FOR Application:Run().

[quote]In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the SystemEvents class.[/quote]

Posted by tpavlovic on 16-Jan-2018 07:19

Progress has its own handler (Windows is exiting.  Is this OK?) so maybe it just breaks the event chain.

Posted by Roger Blanchard on 16-Jan-2018 07:20

That must be the issue. I do not have a wait-for. There is no UI in this module...it is a DB sync manager.

Posted by Roger Blanchard on 16-Jan-2018 07:21

I disabled that with the -wy startup parameter

Posted by Roger Blanchard on 17-Jan-2018 07:12

Matt,

I had to go down the path of using a hidden form with the Application:Run().

Thanks for the pointer.

This thread is closed