public void Disconnect() { if (ec2 != null) { Debug.Assert(RunMonitoring); Debug.Assert(MonitoringThread != null); Debug.Assert(route53 != null); Debug.Assert(s3 != null); Debug.Assert(CloudWatch != null); myTaskQueue.Close(); bool killedTheThread = false; //Shut the thread lock (Ec2Lock) { RunMonitoring = false; } if (!MonitoringThread.Join(10000)) { MonitoringThread.Abort(); killedTheThread = true; } MonitoringThread = null; ec2.Dispose(); ec2 = null; route53.Dispose(); route53 = null; s3.Dispose(); s3 = null; CloudWatch.Dispose(); CloudWatch = null; if (killedTheThread) { throw new ZAwsException("Connection failure, could not close connection gracefully. Might require restart."); } } else { Debug.Assert(!RunMonitoring); Debug.Assert(MonitoringThread == null); } }