Skydiver, on 26 February 2013 - 08:04 PM, said:
This seems to work for me without any deadlock:
using System;
using System.Diagnostics;
using System.Data;
using System.Text;
using System.Net;
using System.Threading;
using System.Net.NetworkInformation;
namespace SimpleCsConsole2012
{
public class Program
{
static void Main()
{
IPAddress ip = new IPAddress(0x7F000001);
byte[] buffer = new byte[8192];
if (ip != null)
{
AutoResetEvent are = new AutoResetEvent(false);
Ping p = new Ping();
p.PingCompleted += (o, e) =>
{
Console.WriteLine("Ping completed...");
((AutoResetEvent)e.UserState).Set();
};
p.SendAsync(ip, 7000, buffer, new PingOptions { Ttl = 64, DontFragment = true }, are);
Console.WriteLine("Waiting...");
are.WaitOne();
Console.WriteLine("Done waiting...");
}
Console.WriteLine("Done.");
}
}
}
Quite odd friend and I appreciate your help very much. I do want to use the asynchronous version of ping I have my reasons for later but the weird part about this code is it deadlocks and THE EVENT NEVER EVENT METHOD CODE NEVER GETS FIRED AT ALL!! How crazy is that? I figured that out using breaks etc.? I wonder why that could possibly be or if this is something totally unrelated to my program?

New Topic/Question
Reply




MultiQuote



|