T
T
to_east2019-08-26 17:14:16
go
to_east, 2019-08-26 17:14:16

Intercepting the shutdown, sleep event in Windows?

Hi all!
The program is launched via vbs via autorun, performs some data processing work,
saves the state in the database in a separate thread with an interval of n seconds. I would like to redo it a little, make it so that at startup
data is loaded from the database into structures, and when the computer shuts down or goes into sleep mode or by pressing Ctrl-C, the structures are saved back to the database.
Signal initialization is something like this

c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)

but only syscall.SIGTERM (Ctrl-C) works.
Somewhere I saw that Windows kills the process without sending an event (but this is not accurate), and therefore the interception fails.
What options?
What about services?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Privalov, 2019-09-07
@negasus

but can't it be that you need to listen to syscall.SIGKILL and syscall.SIGINT? (no Windows at hand)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question