I have a WinForms application that monitors when the system goes into a suspended state (sleep) and when it resumes. For this purpose, the application uses the class SystemEvents. It works great on my car. However, it seems that for some users, event c PowerModes.Resumedoes not always go up. The application receives several PowerModes.Suspendwithout any PowerModes.Resume, between which is strange.
My main question is how can this happen and how to avoid it and make reliable detection of renewal?
The code is pretty simple and basically the following (very shortened):
Imports Microsoft.Win32
Friend Class TehClass
Implements IDisposable
Private Sub New()
AddHandler SystemEvents.PowerModeChanged, AddressOf Me.System_PowerModeChanged
End Sub
Private Sub System_PowerModeChanged(sender As Object, args As PowerModeChangedEventArgs)
Log.Info("Power mode changed: {0}.", args.Mode)
End Sub
' just dropping handler there
End Class
. . TehClass.
:
[2015-09-15 22:38:38,501] Power mode changed: Suspend.
[2015-09-16 07:10:31,106] Power mode changed: Resume.
[2015-09-16 08:54:21,112] Power mode changed: Suspend.
[2015-09-16 09:14:36,252] Power mode changed: Suspend.
[2015-09-16 09:35:21,077] Power mode changed: Suspend.
[2015-09-16 09:55:36,085] Power mode changed: Suspend.
[2015-09-16 10:15:50.122] User reported this log therefore the PC had to be in Working (Resumed) state.
, , - , Resume. , suspend 20 . - "", , , , .., ? "