Esempio n. 1
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (masterSocket != null)
     {
         foreach (int idSlave in masterSocket.getIdSlaves())
         {
             Socket.MasterSocket.Slave slave = Socket.MasterSocket.getSlave(idSlave);
             try
             {
                 slave.cli.Close();
                 slave.clipboard_cli.Close();
                 slave.threadMessage.Abort();
                 slave.taskClip.Dispose();
             }
             catch (Exception exp) { }
         }
     }
 }
Esempio n. 2
0
        //timeout
        void checkConnections()
        {
            if (masterSocket == null)
            {
                return;
            }
            HashSet <int> slavesMissing = new HashSet <int>();

            foreach (int idSlave in masterSocket.getIdSlaves())
            {
                Socket.MasterSocket.Slave slave = Socket.MasterSocket.getSlave(idSlave);
                bool ok = !slave.mustBeDeleted;
                if (ok)
                {
                    try
                    {
                        ok = ok && CommonClasses.SocketMessages.TcpUtilities.isTcpActive(slave.cli);
                        ok = ok && CommonClasses.SocketMessages.TcpUtilities.isTcpActive(slave.clipboard_cli);
                    }
                    catch (Exception exp)
                    {
                        ok = false;
                    }
                }
                if (!ok)
                {
                    slavesMissing.Add(idSlave);
                }
            }


            foreach (int idSlave in slavesMissing)
            {
                Socket.MasterSocket.Slave slave = Socket.MasterSocket.getSlave(idSlave);
                if (idSlave == idSlaveFocus)
                {
                    try{
                        if (!slave.mustBeDeleted)
                        {
                            Socket.MasterSocket.SlaveEnableDisable(idSlave, false);
                        }
                        idSlaveFocus = -1;
                    }catch (Exception e) {}
                }

                try{
                    //lsbSlaves.Items.RemoveByKey(""+idSlave);
                    slave.close();
                }catch (Exception e) {}

                Form1.getForm().Invoke((Action)(() =>
                {
                    List <ListViewItem> itemsList = new List <ListViewItem>();
                    foreach (ListViewItem item in lsbSlaves.Items)
                    {
                        if (slavesMissing.Contains((int)item.Tag))
                        {
                            itemsList.Add(item);
                        }
                    }
                    foreach (ListViewItem item in itemsList)
                    {
                        lsbSlaves.Items.Remove(item);
                    }
                }));

                masterSocket.removeSlave(idSlave);
            }
        }