Ping.SendAsync to reduce UI freezing
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace OpenRA.Network
|
namespace OpenRA.Network
|
||||||
{
|
{
|
||||||
@@ -75,9 +76,21 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
hasBeenPinged = true;
|
hasBeenPinged = true;
|
||||||
var pingSender = new Ping();
|
var pingSender = new Ping();
|
||||||
PingReply reply = pingSender.Send(Address.Split(':')[0]);
|
pingSender.PingCompleted += new PingCompletedEventHandler(pongRecieved);
|
||||||
if (reply != null && reply.Status == IPStatus.Success)
|
AutoResetEvent waiter = new AutoResetEvent(false);
|
||||||
Latency = (int)reply.RoundtripTime;
|
pingSender.SendAsync(Address.Split(':')[0], waiter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pongRecieved(object sender, PingCompletedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Cancelled || e.Error != null)
|
||||||
|
Latency = -1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PingReply pong = e.Reply;
|
||||||
|
if (pong != null && pong.Status == IPStatus.Success)
|
||||||
|
Latency = (int)pong.RoundtripTime;
|
||||||
else
|
else
|
||||||
Latency = -1;
|
Latency = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user