@@ -306,7 +306,7 @@ Public Class WinNUT
306306 End If
307307 Case Microsoft.Win32.PowerModes.Suspend
308308 LogFile.LogTracing( "Windows standby, WinNUT will disconnect" , LogLvl.LOG_NOTICE, Me , WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_GOTOSLEEP))
309- 'UPS_Device.Disconnect ()
309+ UPSDisconnect ()
310310 End Select
311311 End Sub
312312
@@ -328,6 +328,20 @@ Public Class WinNUT
328328 End If
329329 End Sub
330330
331+ ''' <summary>
332+ ''' Prepare application for and handle disconnecting from the UPS.
333+ ''' </summary>
334+ Private Sub UPSDisconnect()
335+ Update_Data.Stop()
336+ Nut_Socket.Disconnect( True )
337+ ReInitDisplayValues()
338+ ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE
339+ LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, Me )
340+ UpdateIcon_NotifyIcon()
341+ RaiseEvent UpdateNotifyIconStr( "Deconnected" , Nothing )
342+ RaiseEvent UpdateBatteryState( "Deconnected" )
343+ End Sub
344+
331345 Private Sub Retrieve_UPS_Datas(sender As Object , e As EventArgs)
332346 Me .Device_Data = UPS_Device.Retrieve_UPS_Datas()
333347 RaiseEvent Data_Updated()
@@ -368,9 +382,9 @@ Public Class WinNUT
368382 e.Cancel = True
369383 Else
370384 LogFile.LogTracing( "Init Disconnecting Before Close WinNut" , LogLvl.LOG_DEBUG, Me )
371- Nut_Socket.Disconnect( True )
372- LogFile.LogTracing( "WinNut Is now Closed" , LogLvl.LOG_DEBUG, Me )
373385 RemoveHandler Microsoft.Win32.SystemEvents.PowerModeChanged, AddressOf SystemEvents_PowerModeChanged
386+ UPSDisconnect()
387+ LogFile.LogTracing( "WinNut Is now Closed" , LogLvl.LOG_DEBUG, Me )
374388 End
375389 End If
376390 End Sub
@@ -718,14 +732,7 @@ Public Class WinNUT
718732
719733 Private Sub Menu_Disconnect_Click(sender As Object , e As EventArgs) Handles Menu_Disconnect.Click
720734 LogFile.LogTracing( "Force Disconnect from menu" , LogLvl.LOG_DEBUG, Me )
721- Update_Data.Stop()
722- Nut_Socket.Disconnect( True )
723- ReInitDisplayValues()
724- ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE
725- LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, Me )
726- UpdateIcon_NotifyIcon()
727- RaiseEvent UpdateNotifyIconStr( "Deconnected" , Nothing )
728- RaiseEvent UpdateBatteryState( "Deconnected" )
735+ UPSDisconnect()
729736 End Sub
730737
731738 Private Sub ReInitDisplayValues()
@@ -1014,6 +1021,7 @@ Public Class WinNUT
10141021
10151022 Private Sub Shutdown_Event() Handles UPS_Device.Shutdown_Condition
10161023 If WinNUT_Params.Arr_Reg_Key.Item( "ImmediateStopAction" ) Then
1024+ UPSDisconnect()
10171025 Shutdown_Action()
10181026 Else
10191027 LogFile.LogTracing( "Open Shutdown Gui" , LogLvl.LOG_DEBUG, Me )
0 commit comments