It is because SendPing sends ping using
pingSender.SendAsync
and exits immediately. At this time there is nothing in
messageDisplay
.
1) Use SendAsync and update richtextbox there itself.
2) Use Send and update richtextbox depending on PingReply.
Your event will work only with SendAsync.
System.Net.NetworkInformation.PingCompletedEventHandler PingCompleted
Occurs when an asynchronous operation to send an Internet Control Message Protocol (ICMP) echo message and receive the corresponding ICMP echo reply message completes or is canceled.