|
using System;
using System.Threading;
using System.Diagnostics;
using Amib.Threading;
namespace Examples
{
/// <summary>
/// Summary description for WaitForIdleExample.
/// </summary>
public class WaitForIdleExample
{
public WaitForIdleExample()
{
}
/// <summary>
/// Example of non disposable caller state
/// </summary>
public bool TestWaitForIdle()
{
SmartThreadPool smartThreadPool = new SmartThreadPool(10, 25, 0);
bool success = false;
for(int i = 0; i < 100; ++i)
{
smartThreadPool.QueueWorkItem(
new WorkItemCallback(this.DoSomeWork),
null);
}
success = !smartThreadPool.WaitForIdle(3500);
success = success && smartThreadPool.WaitForIdle(1000);
smartThreadPool.Shutdown();
return success;
}
private int x = 0;
private object DoSomeWork(object state)
{
Debug.WriteLine(Interlocked.Increment(ref x));
Thread.Sleep(1000);
return 1;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
B.Sc. in Computer Science.
Works as Software Developer.