Guest User

Guest User

  • Tech Writer
  • 529
  • 36.1k

c# thread sleep sending not respond

Apr 20 2021 12:07 PM
 
 
I Will Run This Ping App UI Not Working And Not Respond
 
Here Is Code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Net.NetworkInformation;  
  10. using System.Threading;  
  11. namespace WindowsFormsApp1  
  12. {  
  13. public partial class Form1 : Form  
  14. {  
  15. public static int check = 0;  
  16. static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();  
  17. public Form1()  
  18. {  
  19. InitializeComponent();  
  20. }  
  21. private void button1_Click(object sender, EventArgs e)  
  22. {  
  23. ping();  
  24. }  
  25. public void ping()  
  26. {  
  27. int q = Convert.ToInt32(packet1.Text);  
  28. check = 1;  
  29. int milliseconds = 500;  
  30. byte[] packet = new byte[q];  
  31. Ping myPing = new Ping();  
  32. PingReply reply;  
  33. while (true)  
  34. {  
  35. Thread.Sleep(milliseconds);  
  36. reply = myPing.Send(ping1.Text, milliseconds, packet);  
  37. if (reply.Status == IPStatus.Success)  
  38. {  
  39. result1.AppendText("Reply from = " + reply.Address + " Bytes = " + reply.Buffer.LongLength + " Time = " + reply.RoundtripTime + " TTL = " + reply.Options.Ttl);  
  40. result1.AppendText(Environment.NewLine);  
  41. }  
  42. else  
  43. {  
  44. result1.AppendText(reply.Status.ToString());  
  45. result1.AppendText(Environment.NewLine);  
  46. }  
  47. }  
  48. }  

Answers (3)