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.
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]
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.
GUI client (prowin32.exe, prowin.exe, prowc.exe)
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]
Progress has its own handler (Windows is exiting. Is this OK?) so maybe it just breaks the event chain.
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.
I disabled that with the -wy startup parameter
Matt,
I had to go down the path of using a hidden form with the Application:Run().
Thanks for the pointer.