Skip to content

Instantly share code, notes, and snippets.

@esdrubal esdrubal/AutoResetEventTests.cs Secret
Last active Aug 29, 2015

Embed
What would you like to do?
AutoResetEventTests
using System.Threading;
using System;
using NUnit.Framework;
namespace MonoTests.System.Threading
{
[TestFixture]
class AutoResetEventTests
{
[Test]
public static void SetReset()
{
var ev1 = new AutoResetEvent (false);
var ev2 = new AutoResetEvent (false);
var i = 0;
const int repeatCount = 20;
var threadStart = new ThreadStart (() => {
ev1.Set ();
ev1.Reset ();
ev2.Set ();
int waitResult = WaitHandle.WaitAny (new [] { ev1 },
TimeSpan.FromSeconds (10));
if (waitResult != WaitHandle.WaitTimeout)
Interlocked.Increment (ref i);
});
for (var r = 0; r < repeatCount; r++) {
new Thread (threadStart).Start ();
ev2.WaitOne (2000, false);
}
#if NET_4_0
Assert.AreEqual (repeatCount-1, i);
#else
Assert.AreEqual (0, i);
#endif
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.