当前位置: 首页>>代码示例>>C#>>正文


C# Pool.Release方法代码示例

本文整理汇总了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());
 }
开发者ID:iloktionov,项目名称:CookBook,代码行数:8,代码来源:Pool_DebugFeaturesTests.cs

示例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));
 }
开发者ID:iloktionov,项目名称:CookBook,代码行数:8,代码来源:Pool_DebugFeaturesTests.cs

示例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);
 }
开发者ID:iloktionov,项目名称:CookBook,代码行数:13,代码来源:Pool_DebugFeaturesTests.cs

示例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));
 }
开发者ID:iloktionov,项目名称:CookBook,代码行数:7,代码来源:Pool_DebugFeaturesTests.cs

示例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);
 }
开发者ID:iloktionov,项目名称:CookBook,代码行数:8,代码来源:Pool_StrategyTests.cs

示例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);
        }
开发者ID:iloktionov,项目名称:CookBook,代码行数:21,代码来源:Pool_StrategyTests.cs

示例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);
 }
开发者ID:iloktionov,项目名称:CookBook,代码行数:13,代码来源:Pool_SpeedTests.cs

示例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);
 }
开发者ID:jeffrymorris,项目名称:resource-pools,代码行数:7,代码来源:PoolTest.cs


注:本文中的Pool.Release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。