It is currently April 19th, 2024, 4:26 pm

OnCloseAction not called on Windows shutdown

Get help with creating, editing & fixing problems with skins
Likon
Posts: 6
Joined: September 2nd, 2018, 9:19 pm

OnCloseAction not called on Windows shutdown

Post by Likon »

Hi there.
I'm a long time user of Rainmeter, however this is the first time I come to the forums.

I'm having trouble using OnCloseAction. I need to save some values when the computer shuts down, however OnCloseAction doesn't seem to work when I shutdown Windows. It only works if I manually close Rainmeter.
I understand that if the program is terminated suddenly it will be impossible to call OnCloseAction, however I feel like a Windows shutdown should provide a clean exit from the program.

The exact same problem was described here but unfortunately no solution was given: https://forum.rainmeter.net/viewtopic.php?t=16169&start=10

Here is a minimal working example I used to make sure I'm not messing up anywhere else.

Code: Select all

[Metadata]
Name=CloseActionTest
Author=Likon
Version=1
Description=...

; Main stuff
[Rainmeter]
Update=100
AccurateText=1
SkinWidth=100
SkinHeight=100

OnCloseAction=[!UpdateMeasure MeasureCount]


[Variables]
Counter=1
Inited=0

[MeasureCount]
Measure=Calc
UpdateDivider=-1
DynamicVariables=1
IfCondition=(#Inited# = 1)
IfTrueAction=[!WriteKeyValue Variables Counter (#Counter#+1)][!SetVariable "Counter" (#Counter#+1)]
IfFalseAction=[!SetVariable "Inited" 1]

[MeterCounter]
Meter=String
AntiAlias=1
DynamicVariables=1
Text=#Counter#
X=20
Y=20
Here is my versions information in case it helps:
4.2.0 beta r3097 64-bit (Jun 22 2018) - English (1033)
Windows 10 Pro 1803 64-bit (build 17134) - Portuguese (2070)

Thank you for any help you can provide.
Cheers,

Likon
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: OnCloseAction not called on Windows shutdown

Post by kyriakos876 »

I'm not sure but I don't think rainmeter will have enough time to react. Windows has to terminate 1000 and one things that are more important from rainmeter in what? 1 second? so rainmeter doesn't get time. It just dies. Now you could create a button, that executes the measure, then add a delay bang for 16ms for example, and then call a shut down command.

Or maybe add a [on update action] so Everytime it updates you save your stuff.
Likon
Posts: 6
Joined: September 2nd, 2018, 9:19 pm

Re: OnCloseAction not called on Windows shutdown

Post by Likon »

kyriakos876 wrote:I'm not sure but I don't think rainmeter will have enough time to react. Windows has to terminate 1000 and one things that are more important from rainmeter in what? 1 second? so rainmeter doesn't get time. It just dies. Now you could create a button, that executes the measure, then add a delay bang for 16ms for example, and then call a shut down command.

Or maybe add a [on update action] so Everytime it updates you save your stuff.
Hi Kyriakos, thanks for your reply.

I would like to avoid both of those solutions. The first because I'm just too used to shut down windows in the regular way and the second because there are some things that I need to do only when closing the computer. What i'm actually doing is controlling a Led strip using Rainmeter so besides saving some variable I also need to turn the Leds off when closing (I'll post my skin later when finished :)).

Once in a while there is a program that gets stuck and you see a message from Windows saying that it is waiting for that program before shutting down, so I find it strange that the same does not happen with Rainmeter, after all I just need one update cycle which, for my skin, is around 20 ms.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: OnCloseAction not called on Windows shutdown

Post by kyriakos876 »

Likon wrote:Hi Kyriakos, thanks for your reply.

I would like to avoid both of those solutions. The first because I'm just too used to shut down windows in the regular way and the second because there are some things that I need to do only when closing the computer. What i'm actually doing is controlling a Led strip using Rainmeter so besides saving some variable I also need to turn the Leds off when closing (I'll post my skin later when finished :)).

Once in a while there is a program that gets stuck and you see a message from Windows saying that it is waiting for that program before shutting down, so I find it strange that the same does not happen with Rainmeter, after all I just need one update cycle which, for my skin, is around 20 ms.
Oh I see... Yeah those programs are made that way, for example word, Photoshop, paint etc. need to interrupt the shut down because you might have something precious that you forgot to save. Rainmeter isn't really in the same category so it's just not made that way to interrupt the system shutdown. Sure it can be moded to do so, but I don't think it's possible. I could be wrong though.

I myself use a triple press on the escape button to shutdown my PC and I got used of it pretty easy. Maybe you could do something like that and that which will allow you to do stuff before executing the actual shutdown. Also, please do post when you are done because I want to see how you communicate with the LED you got Arduino or something or is it simpler?
Likon
Posts: 6
Joined: September 2nd, 2018, 9:19 pm

Re: OnCloseAction not called on Windows shutdown

Post by Likon »

kyriakos876 wrote: I myself use a triple press on the escape button to shutdown my PC and I got used of it pretty easy. Maybe you could do something like that and that which will allow you to do stuff before executing the actual shutdown. Also, please do post when you are done because I want to see how you communicate with the LED you got Arduino or something or is it simpler?
I like that idea of the triple press, I might use it.
I'm using an esp8266 (~3€ arduino like with wifi) and a websocket plugin I developed for Rainmeter. I'm streaming the audio signal from the audio level plugin to control the leds to make my home disco :17spot1
Once I have everything finished I'll release the code, though it may still take a while ;)
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: OnCloseAction not called on Windows shutdown

Post by kyriakos876 »

Likon wrote:I like that idea of the triple press, I might use it.
I'm using an esp8266 (~3€ arduino like with wifi) and a websocket plugin I developed for Rainmeter. I'm streaming the audio signal from the audio level plugin to control the leds to make my home disco :17spot1
Once I have everything finished I'll release the code, though it may still take a while ;)
Sounds nice! I look forward to your release!
Likon
Posts: 6
Joined: September 2nd, 2018, 9:19 pm

Re: OnCloseAction not called on Windows shutdown

Post by Likon »

kyriakos876 wrote:Sounds nice! I look forward to your release!
Here you go :D
Although I still havent implemented any solution for this problem we discussed...