public void WaitForDisconnect()
{
if ( Thread.CurrentThread == ioThread ) {
throw new InvalidOperationException( "Cannot call WaitForDisconnect from IoThread." );
}
if ( ioThread != null && ioThread.IsAlive ) {
try {
ioThread.Join();
} catch ( NullReferenceException ) {
} catch ( ThreadStateException ) { }
}
}