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)
                        {
                            Console.WriteLine("Connection attempt [" + (retryCount) + "] of [5] failed, Waiting 2 seconds...");
                            Thread.Sleep(2000);
                        }
                        else
                        {
                            Console.WriteLine("Shutting down... License server could nog be reached");
                            ButterflyEnvironment.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);
                }
            }
            Console.WriteLine("Shut down due to error..");
            if (ButterflyEnvironment.isLive)
            {
                ButterflyEnvironment.Destroy();
            }
        }