Ejemplo n.º 1
0
        /// <summary>
        /// Send task from one client to another for balancing
        /// </summary>
        /// <param name="message"></param>
        void SendTasksToFreeClient(TasksMessage message)
        {
            var min = new KeyValuePair <string, int>(string.Empty, int.MaxValue);

            //find client with min duration
            foreach (var item in clients)
            {
                if (item.Value < min.Value)
                {
                    min = item;
                }
            }

            //calculate duration of tasks in message
            int duration = 0;

            foreach (var item in message.Tasks)
            {
                duration += item.Duration;
            }

            //add this duration to total duration of min client, and sub it from total duration of sender
            clients[message.ClientName] -= duration;
            clients[min.Key]            += duration;

            SendMessageToClient(message, min.Key);
        }
Ejemplo n.º 2
0
        private void DoWork(StartTasksMessage message, CancellationToken token)
        {
            Dictionary <string, List <PerformanceCounter> > taskInfo = new Dictionary <string, List <PerformanceCounter> >();

            while (true)
            {
                if (token.IsCancellationRequested == true)
                {
                    break;
                }


                var tasksMessage = new TasksMessage(TaskManager.GetTasksList(taskInfo));
                ExecuteComplexSendOperation(message.WindowId,
                                            "Task Manager",
                                            () => tasksMessage);


                if (token.IsCancellationRequested)
                {
                    break;
                }
            }
        }