Bonjour à tous,

J'ai creer une petite application qui écoute sur un port en udp pour l'entreprise dans laquelle je travail. Ce soft ce lance à chaque démarrage.

Mais lorsque l'utilisateur veut fermer sa session, il lui marque le message "Termer maintenant" enfin vous voyez :p L'application ne se ferme pas. Le problème se pose sur 300 pc alors si vous pouviez m'aider :-)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public partial class Form1 : Form
    {
        public bool Continue = true;
 
        public UdpClient udpClient;
 
        public Form1()
        {
            InitializeComponent();
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        }
 
        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            ((Form1)sender).Continue = false;
            udpClient.Send(Encoding.UTF8.GetBytes("Close"), Encoding.UTF8.GetBytes("Close").Length, "127.0.0.1", 46870);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            udpClient = new UdpClient(46870);
            //IPEndPoint object will allow us to read datagrams sent from any source.
            IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 46870);
            while (this.Continue == true)
            {
                // Blocks until a message returns on this socket from a remote host.
                Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
 
                string returnData = Encoding.UTF8.GetString(receiveBytes);
 
                if (returnData != "Close")
                {
                    // Uses the IPEndPoint object to determine which of these two hosts responded.
                    MessageForm mf = new MessageForm();
                    mf.richTextBox1.Rtf = returnData;
                    mf.ShowDialog(this);
                    this.ShowInTaskbar = false;
                    this.Visible = false;
                }
            }
            udpClient.Close();
        }
    }