/// <summary>
        /// When changing instanceType for 2+ clients on the same machine, it might has a situation that they will have the same instanceId,
        /// So in this step the MinerManager would detect the conflicts then assign new instanceId when necessary.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="returnedInstanceId"></param>
        /// <returns></returns>
        private int AssignInstanceId(string machineName, MinerClient.InstanceTypes instanceType, int newInstanceId)
        {
            int    assignedInstanceId = newInstanceId;
            string key = machineName + instanceType.ToString() + assignedInstanceId.ToString();

            MinerManager manager = MinerManager.GetInstance();

            while (this.newInstanceIdDictionary.ContainsKey(key) ||
                   manager.IsInstanceIdExists(machineName, instanceType, assignedInstanceId))
            {
                assignedInstanceId++;
                key = machineName + instanceType.ToString() + assignedInstanceId.ToString();
            }

            this.newInstanceIdDictionary[key] = true;
            return(assignedInstanceId);
        }