asternet/Asterisk.2013/Asterisk.NET/Util/ThreadTask.cs

45 lines
948 B
C#
Raw Normal View History

using System;
2014-01-08 14:16:39 +00:00
using AsterNET.FastAGI;
2014-01-08 14:16:39 +00:00
namespace AsterNET.Util
{
/// <summary>
/// A TaskThread sits in a loop, asking the pool for a job, and servicing it.
/// </summary>
internal class ThreadTask : ThreadClass
{
private ThreadPool threadPool;
#region ThreadPool
public ThreadPool ThreadPool
{
get { return threadPool; }
}
#endregion
#region ThreadTask(ThreadPool enclosingInstance, string name)
public ThreadTask(ThreadPool enclosingInstance, string name)
: base(name)
{
this.threadPool = enclosingInstance;
}
#endregion
#region Run()
/// <summary>
/// Get a job from the pool, run it, repeat. If the obtained job is null, we exit the loop and the thread.
/// </summary>
public override void Run()
{
while (true)
{
AGIConnectionHandler job = ThreadPool.obtainJob();
if (job == null)
break;
job.Run();
}
}
#endregion
}
}