public static void DistributerThread(SendToDistributerConstruct p_send_to_disributer_construct, object p_distributer_pulse_object
                                             , Dictionary <int, KeyValuePair <Thread, ServerWorkerData> > p_all_workers_data, object p_all_workers_data_lock)
        {
            Dictionary <int, Thread> all_mini_threads = new Dictionary <int, Thread>();
            object all_mini_threads_lock = new object();

            while (true)
            {
                lock (p_distributer_pulse_object)
                {
                    if (!p_send_to_disributer_construct.send_to_distribuer_queue_flag)
                    {
                        Monitor.Wait(p_distributer_pulse_object);
                    }

                    if (p_send_to_disributer_construct.send_to_distribuer_queue_flag)
                    {
                        if (p_send_to_disributer_construct.send_to_distributer_queue.Count > 0)
                        {
                            MessageToDistributer object_to_do = p_send_to_disributer_construct.send_to_distributer_queue.Dequeue();
                            if (object_to_do.Get_type_of_message_to_distributer == TypeOfMessageToDistributer.CancelAServerWorkerRequest)
                            {
                                int thread_id_to_cancel = object_to_do.Get_thread_id;
                                int mini_thread_id      = HelperFunctions.GetGUID();

                                Thread cancelling_thread = new Thread(() => CancelAServerWorkerThread(p_all_workers_data, p_all_workers_data_lock, thread_id_to_cancel
                                                                                                      , all_mini_threads_lock, all_mini_threads, mini_thread_id));

                                lock (all_mini_threads_lock)
                                {
                                    all_mini_threads.Add(mini_thread_id, cancelling_thread);
                                }
                                cancelling_thread.Start();
                            }

                            else if (object_to_do.Get_type_of_message_to_distributer == TypeOfMessageToDistributer.MessageToServerWorker)
                            {
                                int thread_id_to_get_message = object_to_do.Get_thread_id;
                                int mini_thread_id           = HelperFunctions.GetGUID();

                                Thread transport_thread = new Thread(() => TransferAMessageToAServerWorkerThread(object_to_do, thread_id_to_get_message, p_all_workers_data_lock,
                                                                                                                 p_all_workers_data, all_mini_threads_lock, all_mini_threads, mini_thread_id));

                                lock (all_mini_threads_lock)
                                {
                                    all_mini_threads.Add(mini_thread_id, transport_thread);
                                }
                                transport_thread.Start();
                            }
                        }
                        else
                        {
                            p_send_to_disributer_construct.send_to_distribuer_queue_flag = false;
                        }
                    }
                }
            }
        }
        public SendData(SendToDistributerConstruct p_send_to_distributer_construct, IsLoggedIn p_is_logged_in, GetOnlineUserThreadID p_get_online_user_thread_id
                        , GetAThreadUserName p_get_thread_user_name, IsThereUnauthWorkerThread p_is_there_unauth_worker_thread, object p_distributer_pulse_object)
        {
            send_to_distributer_construct = p_send_to_distributer_construct;
            distributer_pulse_object      = p_distributer_pulse_object;

            is_logged_in = p_is_logged_in;
            get_online_user_thread_id     = p_get_online_user_thread_id;
            get_thread_user_name          = p_get_thread_user_name;
            is_there_unauth_worker_thread = p_is_there_unauth_worker_thread;
        }
        public ServerCore(Dictionary <int, UserData> p_all_users_logged_in, StartClientFriendChangedStatusInformDialog p_start_client_friend_changed_status_inform_dialog, StartSendToClinetFormalMessage p_start_send_to_client_fromal_message
                          , List <int> p_all_threads, SendToDistributerConstruct p_send_to_distributer_construct, object p_distributer_pulse_object)
        {
            int h = 0;

            while (h < 4)
            {
                try
                {
                    controller = new DB_Controller();
                    h          = 0;
                    break;
                }
                catch (System.Data.SqlClient.SqlException)
                {
                    h++;
                    continue;
                }
            }
            if (h > 3)
            {
                Console.WriteLine("Error in working with database");
                try
                {
                    Environment.Exit(5);
                }
                catch
                {
                }
                Thread.CurrentThread.Abort();
                return;
            }

            start_client_friend_changed_status_inform_dialog = p_start_client_friend_changed_status_inform_dialog;
            thread_manager = new ThreadManager(p_all_threads);
            start_send_to_client_fromal_message = p_start_send_to_client_fromal_message;

            user_manager = new UserManager(p_all_users_logged_in, new DB_IsThereUserPass(controller.IsThereUserPass), new DB_GetUserFriendsList(controller.GetUserFriendsList)
                                           , new DB_IsThereUser(controller.IsThereUser), new RemoveThread(SC_RemoveThread), new DB_CreateNewUser(controller.AddNewUser)
                                           , new StartClientFriendChangedStatusInformDialog(SC_StartClientFriendChangedStatusInformDialog), new StartSendToClinetFormalMessage(SC_StartSendToClinetFormalMessage)
                                           , new CreateOfflineMessage(SC_DB_AddOfflineMessage), new RegisterThread(SC_RegisterAThread));

            send_data = new SendData(p_send_to_distributer_construct, new IsLoggedIn(SC_IsLoggedIn), new GetOnlineUserThreadID(SC_GetOnlineUserThreadID),
                                     new GetAThreadUserName(SC_GetAThreadUserName), new IsThereUnauthWorkerThread(SC_IsThereUnauthWorkerThread), p_distributer_pulse_object);
        }