public virtual void Start()
{
if (_connectionManagerThread == null || _connectionManagerThread.ThreadState == ThreadState.Stopped)
{
_connectionManagerThread = new Thread(ConnectionManagerThreadStart)
{
Name =
String.Format(CultureInfo.InvariantCulture,
"ConnectionManager_{0}", UniqueId)
};
}
else if (_connectionManagerThread.ThreadState == ThreadState.Running)
{
throw new ThreadStateException("The request handling process is already running.");
}
if (_connectionManagerThread.ThreadState != ThreadState.Unstarted)
{
throw new ThreadStateException("The request handling process was not properly initialized so it could not be started.");
}
_connectionManagerThread.Start();
long waitTime = DateTime.Now.Ticks + TimeSpan.TicksPerSecond * 10;
while (RunState != State.Started)
{
Thread.Sleep(100);
if (DateTime.Now.Ticks > waitTime)
{
throw new TimeoutException("Unable to start the request handling process.");
}
}
}