本文整理汇总了C#中System.Threading.CountdownEvent.TryAddCount方法的典型用法代码示例。如果您正苦于以下问题:C# CountdownEvent.TryAddCount方法的具体用法?C# CountdownEvent.TryAddCount怎么用?C# CountdownEvent.TryAddCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.CountdownEvent
的用法示例。
在下文中一共展示了CountdownEvent.TryAddCount方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryAddCount_HasBeenSet
public void TryAddCount_HasBeenSet ()
{
var ev = new CountdownEvent (0);
Assert.IsFalse (ev.TryAddCount (1), "#1");
ev = new CountdownEvent (1);
ev.Signal ();
Assert.IsFalse (ev.TryAddCount (1), "#2");
ev = new CountdownEvent (2);
ev.Signal (2);
Assert.IsFalse (ev.TryAddCount (66), "#3");
}
示例2: TryAddCount_Invalid
public void TryAddCount_Invalid ()
{
var ev = new CountdownEvent (1);
try {
ev.TryAddCount (0);
Assert.Fail ("#1");
} catch (ArgumentOutOfRangeException) {
}
try {
ev.TryAddCount (-1);
Assert.Fail ("#2");
} catch (ArgumentOutOfRangeException) {
}
}
示例3: Dispose
public void Dispose ()
{
var ce = new CountdownEvent (1);
ce.Dispose ();
Assert.AreEqual (1, ce.CurrentCount, "#0a");
Assert.AreEqual (1, ce.InitialCount, "#0b");
Assert.IsFalse (ce.IsSet, "#0c");
try {
ce.AddCount ();
Assert.Fail ("#1");
} catch (ObjectDisposedException) {
}
try {
ce.Reset ();
Assert.Fail ("#2");
} catch (ObjectDisposedException) {
}
try {
ce.Signal ();
Assert.Fail ("#3");
} catch (ObjectDisposedException) {
}
try {
ce.TryAddCount ();
Assert.Fail ("#4");
} catch (ObjectDisposedException) {
}
try {
ce.Wait (5);
Assert.Fail ("#4");
} catch (ObjectDisposedException) {
}
try {
var v = ce.WaitHandle;
Assert.Fail ("#5");
} catch (ObjectDisposedException) {
}
}
示例4: TryAddCountTestCase
public void TryAddCountTestCase()
{
var evt = new CountdownEvent (5);
Assert.IsTrue(evt.TryAddCount(2), "#1");
evt.Signal(7);
Assert.IsFalse(evt.TryAddCount(), "#2");
}
示例5: CurrentCountTestCase
public void CurrentCountTestCase()
{
var evt = new CountdownEvent (5);
Assert.AreEqual(5, evt.CurrentCount, "#1");
evt.AddCount();
Assert.AreEqual(6, evt.CurrentCount, "#2");
evt.TryAddCount(2);
Assert.AreEqual(8, evt.CurrentCount, "#3");
evt.Signal(4);
Assert.AreEqual(4, evt.CurrentCount, "#4");
evt.Reset();
Assert.AreEqual(5, evt.CurrentCount, "#5");
}