1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
+
4
5
using System ;
6
+ using System . Diagnostics ;
5
7
using System . Threading ;
6
8
7
9
public class AutoResetEventCtor
@@ -70,8 +72,8 @@ public bool PosTest2()
70
72
{
71
73
bool retVal = true ;
72
74
AutoResetEvent are ;
73
- long ticksBefore ;
74
- long ticksAfter ;
75
+ Stopwatch sw ;
76
+ long elapsedTicks ;
75
77
76
78
TestLibrary . TestFramework . BeginScenario ( "PosTest1: AutoResetEvent.Ctor(false)" ) ;
77
79
@@ -80,19 +82,20 @@ public bool PosTest2()
80
82
// true means that the initial state should be signaled
81
83
are = new AutoResetEvent ( false ) ;
82
84
83
- ticksBefore = DateTime . Now . Ticks ;
85
+ sw = Stopwatch . StartNew ( ) ;
84
86
85
87
// verify that the autoreset event is signaled
86
88
// if it is not signaled the following call will block for ever
87
89
TestLibrary . TestFramework . LogInformation ( "Calling AutoResetEvent.WaitOne()... if the event is signaled it will not wait long enough" ) ;
88
90
are . WaitOne ( c_MILLISECONDS_TOWAIT ) ;
89
91
90
- ticksAfter = DateTime . Now . Ticks ;
92
+ sw . Stop ( ) ;
93
+ elapsedTicks = sw . Elapsed . Ticks ;
91
94
92
- if ( c_DELTA < Math . Abs ( ( ticksAfter - ticksBefore ) - ( c_MILLISECONDS_TOWAIT * 10000 ) ) )
95
+ if ( c_DELTA < Math . Abs ( elapsedTicks - ( c_MILLISECONDS_TOWAIT * 10000 ) ) )
93
96
{
94
97
TestLibrary . TestFramework . LogError ( "002" , "AutoResetEvent did not wait long enough... this implies that the parameter was not respected." ) ;
95
- TestLibrary . TestFramework . LogError ( "002" , " WaitTime=" + ( ticksAfter - ticksBefore ) + " (ticks)" ) ;
98
+ TestLibrary . TestFramework . LogError ( "002" , " WaitTime=" + elapsedTicks + " (ticks)" ) ;
96
99
TestLibrary . TestFramework . LogError ( "002" , " Execpted=" + ( c_MILLISECONDS_TOWAIT * 10000 ) + " (ticks)" ) ;
97
100
TestLibrary . TestFramework . LogError ( "002" , " Acceptable Delta=" + c_DELTA + " (ticks)" ) ;
98
101
retVal = false ;
0 commit comments