示例#1
0
 private void btnSenden_Click(object sender, RoutedEventArgs e)
 {
     if (SendeDaten.Text != "")
     {
         string s = nickname.Text + ": " + SendeDaten.Text;
         try
         {
             byte[] buffer = Encoding.ASCII.GetBytes(s);
             Dispatcher.Invoke(DispatcherPriority.Normal, (Action) delegate() { clientSocket.Send(buffer); });
             Chat.Text += s + "\n";
             SendeDaten.Clear();
         }
         catch
         {
             SendeDaten.Clear();
             Dispatcher.Invoke(DispatcherPriority.Normal, (Action) delegate() { UpdateText("Sendefehler - ist eine Verbindung zum Server vorhanden?\n"); });
         }
     }
 }
示例#2
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     for (int i = 0; i < 1; i--)
     {
         int    dat = rnd.Next(1, 500);
         string s   = dat.ToString();
         try
         {
             byte[] buffer = Encoding.ASCII.GetBytes(s);
             Dispatcher.Invoke(DispatcherPriority.Normal, (Action) delegate() { clientSocket.Send(buffer); });
             Console.WriteLine(s);
             SendeDaten.Clear();
         }
         catch
         {
             SendeDaten.Clear();
             // Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate () { UpdateText("Sendefehler - ist eine Verbindung zum Server vorhanden?\n"); });
         }
         int milliseconds = 200;
         Thread.Sleep(milliseconds);
     }
 }