public void Disconnect()
{
// DeRegister connection in SpeedMonitor
SpeedMonitor.Instance.DeRegisterConnection(this);
keepAlive = false;
int MaxWait = 1000; // 1 sec
int AccWait = 0; // Accumulated wait
int WaitStep = 10; // 10ms between checks
while (!idle && AccWait < MaxWait)
{
AccWait += WaitStep;
Thread.Sleep(WaitStep);
}
Close();
}