2017-11-14 9 views
1

viewmodelでReactiveUIを使用してバインディングを表示するUWPアプリケーションがあります。ユーザーがアプリに記録されます場合は(コマンドでログが実行される)以下のメソッドが呼び出されます:UWPアプリケーションの中断モード

private void RegisterActivityTrackingFunctionality() 
    { 
     Container = _container; 
     Container.Resolve<IDialogService>().IsActive = true; 
     _dispatcher = Window.Current.Dispatcher; 

     Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed; 
     Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown; 
     _timer = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(30)).Subscribe(_ => CheckActivityTime()); 
    } 

タイマーは、アプリケーションでのユーザーの活動を監視するために作成されます。ユーザーが15分間以上アクティブでない場合、ユーザーはアプリケーションからログオフします。基本的にはこの方法CheckActivityTime()は、この目的のために呼び出されます。

private void CheckActivityTime() 
    { 
     _logger.Info("In a CheckActivityTime Method"); 
     if (Container.Resolve<TokenHolder>().IsActivityTimeElapsed) 
     { 
      if (_timer != null) 
      { 
       _timer.Dispose(); 
      } 

      Task.Run(async() => await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, 
      () => 
      { 
       try 
       { 
        Container.Resolve<IDialogService>().IsActive = false; 

        var dialogService = Container.Resolve<IContentDialogService>(); 

        if (dialogService.CurrentContentDialog != null) 
        { 
         dialogService.CurrentContentDialog.Hide(); 
        } 

        var shellViewModel = Container.Resolve<ShellViewModel>(); 

        if (shellViewModel.Router.NavigationStack.Count > 1) 
        { 
         shellViewModel.Router.NavigateBack.Execute(null); 
        } 
       } 
       catch (Exception ex) 
       { 
        _logger.Error("The unhandled exception occured in UI thread for logout mechanism", ex); 
       } 
      } 
      )); 
     } 
    } 

問題はそのようなものです:アプリがサスペンドモードになると非アクティブ時間が15分を超えた場合、それは常にユーザーをログアウトしません。 誰も私に説明することができます、何が問題ですか? タイマー設定に何か問題がありますか?あるいは、UIスレッドでログアウト操作をしないでください。

答えて

1

あなたができることは、サスペンド状態からアプリを再開するたびに呼び出されるアプリのOnResumingイベントにハンドラをアタッチしてから、Activitytimeをチェックし、そこでアプリをロックすることです。

Application.Current.Resuming += new EventHandler<Object>(App_Resuming); 
+0

問題はタイマーが正常に機能することですが、非アクティブ時間を超えてもログアウトしないことがあります。この問題をローカルで再現できず、ローカルで正しく動作するようになりました。不適当な申請作業のすべての事例が生産から受領された。 –

関連する問題