88
99using System ;
1010using System . Threading . Tasks ;
11- using System . Windows ;
12- using System . Windows . Threading ;
11+ using System . Timers ;
1312using SafeExamBrowser . Configuration . Contracts . Integrity ;
1413using SafeExamBrowser . Logging . Contracts ;
1514
@@ -19,7 +18,7 @@ internal class IntegrityResponsibility : RuntimeResponsibility
1918 {
2019 private readonly IIntegrityModule integrityModule ;
2120 private readonly Action shutdown ;
22- private readonly DispatcherTimer timer ;
21+ private readonly Timer timer ;
2322
2423 public IntegrityResponsibility (
2524 IIntegrityModule integrityModule ,
@@ -29,7 +28,7 @@ public IntegrityResponsibility(
2928 {
3029 this . integrityModule = integrityModule ;
3130 this . shutdown = shutdown ;
32- this . timer = new DispatcherTimer ( DispatcherPriority . Normal , Application . Current . Dispatcher ) ;
31+ this . timer = new Timer ( ) ;
3332 }
3433
3534 public override void Assume ( RuntimeTask task )
@@ -47,18 +46,25 @@ public override void Assume(RuntimeTask task)
4746
4847 private void StartIntegrityMonitoring ( )
4948 {
50- timer . Interval = TimeSpan . FromSeconds ( 5 ) ;
51- timer . Tick += Timer_Tick ;
49+ const int FIVE_SECONDS = 5000 ;
50+
51+ timer . AutoReset = false ;
52+ timer . Interval = FIVE_SECONDS ;
53+ timer . Elapsed += Timer_Elapsed ;
5254 timer . Start ( ) ;
55+
56+ Logger . Info ( "Started monitoring runtime integrity." ) ;
5357 }
5458
5559 private void StopIntegrityMonitoring ( )
5660 {
5761 timer . Stop ( ) ;
58- timer . Tick -= Timer_Tick ;
62+ timer . Elapsed -= Timer_Elapsed ;
63+
64+ Logger . Info ( "Stopped monitoring runtime integrity." ) ;
5965 }
6066
61- private void Timer_Tick ( object sender , EventArgs e )
67+ private void Timer_Elapsed ( object sender , ElapsedEventArgs e )
6268 {
6369 Logger . Info ( "Attempting to verify runtime integrity..." ) ;
6470
@@ -70,6 +76,8 @@ private void Timer_Tick(object sender, EventArgs e)
7076 {
7177 Logger . Warn ( "Failed to verify runtime integrity!" ) ;
7278 }
79+
80+ timer . Start ( ) ;
7381 }
7482
7583 private void HandleRuntimeIntegrityStatus ( bool isValid )
@@ -82,6 +90,8 @@ private void HandleRuntimeIntegrityStatus(bool isValid)
8290 {
8391 Logger . Error ( "Runtime integrity is compromised!" ) ;
8492
93+ StopIntegrityMonitoring ( ) ;
94+
8595 Task . Run ( ( ) =>
8696 {
8797 if ( SessionIsRunning )
0 commit comments