private void DoHealthChecks() { while (keepThreadAlive) { bool keepConnecting = true; while (state != ConnectionState.open && keepConnecting) { if (state != ConnectionState.connecting && state != ConnectionState.open) { state = ConnectionState.connecting; connection.reset(); Thread.Sleep(1000); addPacketHandelers(); connection.openConnection(); } while (state == ConnectionState.connecting) { Thread.Sleep(1000); } if (state == ConnectionState.failed || state == ConnectionState.closed) { retryCount += 1; if (retryCount <= 5) { Logging.WriteLine("Connection attempt [" + (retryCount) + "] of [5] failed, Waiting 2 seconds..."); Thread.Sleep(2000); } else { Logging.WriteLine("Shutting down... License server could nog be reached"); FirewindEnvironment.PreformShutDown(true); this.keepThreadAlive = false; keepConnecting = false; } } else if (state == ConnectionState.open) { keepConnecting = false; } } while (state == ConnectionState.open && keepThreadAlive) { this.retryCount = 0; connection.processSyncedMessages(); Thread.Sleep(10); } } Logging.WriteLine("Shut down due to error.."); if (FirewindEnvironment.isLive) { FirewindEnvironment.Destroy(); } }