本文整理汇总了C#中Pool.Release方法的典型用法代码示例。如果您正苦于以下问题:C# Pool.Release方法的具体用法?C# Pool.Release怎么用?C# Pool.Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pool
的用法示例。
在下文中一共展示了Pool.Release方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_ReleaseTwiceWithAcquire
public void Test_ReleaseTwiceWithAcquire()
{
var obj = new object();
var pool = new Pool<object>(() => obj, AccessStrategy.LIFO, LoadingStrategy.Eager, 1)
.AttachDebugger(new ReleaseDebugger<object>(state => { throw new InvalidOperationException(); }));
pool.Release(pool.Acquire());
pool.Release(pool.Acquire());
}
示例2: Test_ReleaseTwice
public void Test_ReleaseTwice()
{
var pool = new Pool<object>(() => new object(), AccessStrategy.LIFO, LoadingStrategy.Eager, 1)
.AttachDebugger(new ReleaseDebugger<object>(state => { throw new InvalidOperationException(); }));
object obj = pool.Acquire();
pool.Release(obj);
Assert.Throws<InvalidOperationException>(() => pool.Release(obj));
}
示例3: Test_ReleaseEqualObjects
public void Test_ReleaseEqualObjects()
{
var pool = new Pool<string>(() => new string(new[] { 'a', 'b', 'c' }), AccessStrategy.LIFO, LoadingStrategy.Eager, 2)
.AttachDebugger(new ReleaseDebugger<string>(state => { throw new InvalidOperationException(); }));
string s1 = pool.Acquire();
string s2 = pool.Acquire();
Assert.AreEqual(s1, s2);
Assert.AreEqual(s1.GetHashCode(), s2.GetHashCode());
pool.Release(s1);
pool.Release(s2);
Assert.AreEqual(2, pool.Allocated);
Assert.AreEqual(2, pool.Available);
}
示例4: Test_ReleaseAllocatedGarbage
public void Test_ReleaseAllocatedGarbage()
{
var obj = new object();
var pool = new Pool<object>(() => obj, AccessStrategy.LIFO, LoadingStrategy.Eager, 1)
.AttachDebugger(new ReleaseDebugger<object>(state => { throw new InvalidOperationException(); }));
Assert.Throws<InvalidOperationException>(() => pool.Release(obj));
}
示例5: Test_Lazy_MinimalAllocations
public void Test_Lazy_MinimalAllocations()
{
var pool = new Pool<object>(() => new object(), AccessStrategy.LIFO, LoadingStrategy.Lazy, 3);
for (int i = 0; i < 100; i++)
pool.Release(pool.Acquire());
Assert.AreEqual(1, pool.Allocated);
Assert.AreEqual(1, pool.Available);
}
示例6: Test_LazyExpanding
public void Test_LazyExpanding()
{
var pool = new Pool<object>(() => new object(), AccessStrategy.LIFO, LoadingStrategy.LazyExpanding, 3);
Assert.AreEqual(0, pool.Allocated);
Assert.AreEqual(0, pool.Available);
object o1 = pool.Acquire();
object o2 = pool.Acquire();
Assert.AreEqual(2, pool.Allocated);
Assert.AreEqual(0, pool.Available);
pool.Release(o1);
pool.Release(o2);
Assert.AreEqual(2, pool.Allocated);
Assert.AreEqual(2, pool.Available);
pool.Acquire();
pool.Acquire();
Assert.AreEqual(3, pool.Allocated);
Assert.AreEqual(1, pool.Available);
}
示例7: Test_Speed
public void Test_Speed()
{
var pool = new Pool<object>(() => new object(), AccessStrategy.LIFO, LoadingStrategy.Eager, 1);
long cycles = 0;
TimeSpan testTime = TimeSpan.FromSeconds(1);
var sw = Stopwatch.StartNew();
while (sw.Elapsed < testTime)
{
pool.Release(pool.Acquire());
cycles++;
}
Console.Out.WriteLine("Done {0} Acquire-Release cycles in 1 second.", cycles);
}
示例8: TestRelease
public void TestRelease()
{
_pool = new Pool<Connection>(10, _factory, LoadingMode.Lazy, AccessMode.FIFO);
var connection = _pool.Acquire();
Assert.IsNotNull(connection);
_pool.Release(connection);
}