@@ -106,14 +106,20 @@ public bool Initialize()
106106
107107 protected override void OnStart ( string [ ] args )
108108 {
109- if ( ! Initialize ( ) )
109+ try
110110 {
111+ if ( ! Initialize ( ) )
112+ throw new Exception ( "Service failed to start!" ) ;
113+
114+ IsDisposed = false ;
115+ }
116+ catch ( Exception e )
117+ {
118+ Logger . Fatal ( e ) ;
111119 ExitCode = 1 ;
112120 Stop ( ) ;
113- throw new Exception ( "Service failed to start!" ) ;
121+ throw ;
114122 }
115-
116- IsDisposed = false ;
117123 }
118124
119125 protected override void OnStop ( )
@@ -136,16 +142,20 @@ protected void OnSuspend()
136142
137143 protected override bool OnPowerEvent ( PowerBroadcastStatus powerStatus )
138144 {
145+ Logger . Debug ( "Power Event: {0}" , powerStatus ) ;
146+
139147 switch ( powerStatus )
140148 {
141149 case PowerBroadcastStatus . QuerySuspendFailed :
142150 OnStart ( null ) ;
143151 break ;
144152
145153 case PowerBroadcastStatus . ResumeAutomatic :
154+ OnStart ( null ) ;
155+ break ;
156+
146157 case PowerBroadcastStatus . ResumeCritical :
147158 case PowerBroadcastStatus . ResumeSuspend :
148- OnStart ( null ) ;
149159 break ;
150160
151161 case PowerBroadcastStatus . QuerySuspend :
@@ -181,6 +191,16 @@ public void Finalize(ComputerStateType state = ComputerStateType.Shutdown)
181191 _configManager ? . Dispose ( ) ;
182192 _cache ? . Clear ( ) ;
183193
194+ _timerManager = null ;
195+ _deviceManager = null ;
196+ _temperatureManager = null ;
197+ _sensorManager = null ;
198+ _deviceManager = null ;
199+ _effectManager = null ;
200+ _speedControllerManager = null ;
201+ _configManager = null ;
202+ _cache = null ;
203+
184204 Dispose ( ) ;
185205 IsDisposed = true ;
186206
@@ -219,7 +239,7 @@ private void ApplyComputerStateProfile(ComputerStateType state)
219239 controller . SetSpeed ( port . Id , profile . Speed . Value ) ;
220240
221241 var effectByte = controller . GetEffectByte ( profile . EffectType ) ;
222- if ( effectByte . HasValue )
242+ if ( effectByte . HasValue && profile . EffectColors != null )
223243 controller . SetRgb ( port . Id , effectByte . Value , profile . EffectColors ) ;
224244
225245 if ( state == ComputerStateType . Boot && ( profile . Speed . HasValue || effectByte . HasValue ) )
@@ -326,6 +346,9 @@ public bool DeviceRgbTimerCallback()
326346 {
327347 foreach ( var ( port , colors ) in colorMap )
328348 {
349+ if ( colors == null )
350+ continue ;
351+
329352 var controller = _deviceManager . GetController ( port ) ;
330353 var effectByte = controller ? . GetEffectByte ( effect . EffectType ) ;
331354 if ( effectByte == null )
@@ -349,7 +372,7 @@ public bool LoggingTimerCallback()
349372 if ( data == null )
350373 continue ;
351374
352- Logger . Trace ( "Port {0} data: {1}" , port , data ) ;
375+ Logger . Debug ( "Port {0} data: {1}" , port , data ) ;
353376 }
354377 }
355378
@@ -360,7 +383,7 @@ public bool LoggingTimerCallback()
360383 var value = _temperatureManager . GetSensorValue ( sensor . Identifier ) ;
361384 if ( float . IsNaN ( value ) )
362385 continue ;
363- Logger . Trace ( "Sensor \" {0}\" value: {1}" , sensor . Identifier , value ) ;
386+ Logger . Debug ( "Sensor \" {0}\" value: {1}" , sensor . Identifier , value ) ;
364387 }
365388 }
366389
0 commit comments