Exemple #1
0
        /// <summary>
        /// this methode create a task witch always listen to new messages from server.
        /// when new message recived it notify all methodes(settings and logs)
        /// </summary>
        public void StartListenToServer()
        {
            Task task = new Task(() =>
            {
                while (this.listenToServer) //if no connection to server-stop
                {                           //the try catch is if server disconnected
                    try
                    {
                        string data = basicClient.ReadDataFromServer();
                        ServerMassages(this, ServerDataReciecedEventArgs.FromJSON(data));
                    }
                    catch (Exception)
                    {
                        ServerMassages(this, new ServerDataReciecedEventArgs("Log", "2:Disconnected from server-bye"));
                        Disconnect();
                        break;
                    }
                }
            });

            task.Start();
        }