@@ -36,7 +36,7 @@ private enum Result
3636 None = 0 ,
3737
3838 /// <summary>
39- /// Rrequest is OK.
39+ /// Request is OK.
4040 /// </summary>
4141 OK ,
4242
@@ -85,7 +85,7 @@ private static bool TryFindReport(Windows.Foundation.Collections.ValueSet messag
8585 /// <summary>
8686 /// Interval in seconds
8787 /// </summary>
88- public float Interval { get ; set ; } = 0.1F ;
88+ public float Interval { get ; set ; } = 0.5F ;
8989
9090 #endregion
9191
@@ -131,13 +131,13 @@ public BrightnessConnector()
131131 /// <param name="onBrightnessChanged">Action to be invoked when brightness changed</param>
132132 /// <param name="onError">Action to be invoked when error occurred</param>
133133 /// <param name="onContinue">Action to be invoked when continuation of AppService is determined</param>
134- public virtual async Task InitiateAsync ( Action < int > onBrightnessChanged , Action < string > onError , Func < bool > onContinue )
134+ public virtual Task InitiateAsync ( Action < int > onBrightnessChanged , Action < string > onError , Func < bool > onContinue )
135135 {
136136 this . _onBrightnessChanged = onBrightnessChanged ?? throw new ArgumentNullException ( nameof ( onBrightnessChanged ) ) ;
137137 this . _onError = onError ?? throw new ArgumentNullException ( nameof ( onError ) ) ;
138138 this . _onContinue = onContinue ?? throw new ArgumentNullException ( nameof ( onContinue ) ) ;
139139
140- await ConnectAsync ( true ) ;
140+ return ConnectAsync ( true ) ;
141141 }
142142
143143 private AppService . AppServiceConnection _appServiceConnection ;
@@ -169,11 +169,14 @@ public virtual async Task<bool> OpenAsync()
169169 _appServiceConnection . ServiceClosed += OnAppServiceConnectionServiceClosed ;
170170 return true ;
171171
172- default :
172+ case not AppService . AppServiceConnectionStatus . AppUnavailable :
173+ // AppServiceConnectionStatus.AppUnavailable means temporarily unavailable and
174+ // thus it is excluded because AppServiceConnection can be available later.
173175 // https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.appservice.appserviceconnectionstatus
174- if ( status is not AppService . AppServiceConnectionStatus . AppUnavailable )
175- _isAvailable = false ;
176+ _isAvailable = false ;
177+ goto default ;
176178
179+ default :
177180 _onError ? . Invoke ( $ "Failed: { status } ") ;
178181 return false ;
179182 }
@@ -235,17 +238,13 @@ private void OnAppServiceConnectionRequestReceived(AppService.AppServiceConnecti
235238
236239 private async void OnAppServiceConnectionServiceClosed ( AppService . AppServiceConnection sender , AppService . AppServiceClosedEventArgs args )
237240 {
238- // AppService closes when around 25 seconds has elapsed after it opened.
241+ // AppService closes after 25 seconds has elapsed. It is explained as that AppService
242+ // is executed as background task.
239243 Debug . WriteLine ( "ServiceClosed" ) ;
240244 ReleaseAppServiceConnection ( ) ;
241245
242- if ( _isMultiple )
243- {
244- await Task . Delay ( TimeSpan . FromSeconds ( Interval ) ) ;
245-
246- if ( _onContinue . Invoke ( ) )
247- await ConnectAsync ( true ) ;
248- }
246+ if ( _onContinue . Invoke ( ) )
247+ await ConnectAsync ( _isMultiple ) ;
249248 }
250249
251250 private void ReleaseAppServiceConnection ( )
0 commit comments