I am new to programing and can not find or know what to search for to debug the thread that is started with the SendAsync Method. The code works good using the Send Method but when using SendAsync it goes to waiter.WaitOne() but i never get the callback (I think thats what its called) to myPing_PingCompleted. So two questions how do I debug the code when it starts a new thread. I am using C# Express so it may not have all the debuging tools as VS. and any idea where I am going wrong in my code. Thanks
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net.NetworkInformation;
using System.Threading;
using System.Net;
private void btnPingAsync_Click(object sender, EventArgs e)
{
string bIP = txtStartIP.Text;
string eIP = txtEndIP.Text;
int timeOut;
int cnt = 0;
if (eIP == null) eIP = bIP;
Ping myPing = new Ping();
PingOptions parmPing = new PingOptions();
AutoResetEvent waiter = new AutoResetEvent(false);
myPing.PingCompleted +=new PingCompletedEventHandler(myPing_PingCompleted);
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] dataBuffer = Encoding.ASCII.GetBytes(data);
if (!int.TryParse(txtTimeOut.Text, out timeOut)) timeOut = 120;
parmPing.DontFragment = true;
parmPing.Ttl = 32;
pbQueueStatus.Minimum = 0;
pbQueueStatus.Step = 10;
pbQueueStatus.Value = 0;
pbQueueStatus.Style = ProgressBarStyle.Continuous;
if (verify.ValidIPAddress(bIP) && verify.ValidIPAddress(eIP))
{
IPQueue = build.IPAddressQueue(bIP, eIP);
pbQueueStatus.Maximum = IPQueue.Count;
pbQueueStatus.TopLevelControl.UseWaitCursor= true;
pbQueueStatus.Visible = true;
while (IPQueue.Count > 0)
{
myPing.SendAsync(IPQueue.Dequeue(), timeOut, dataBuffer, parmPing, waiter);
waiter.WaitOne();
if (++cnt > 10)
{
pbQueueStatus.PerformStep();
cnt = 0;
}
}
}
}
private void myPing_PingCompleted(Object sender, PingCompletedEventArgs e)
{
PingReply reply = e.Reply;
((AutoResetEvent)e.UserState).Set();
if (reply .Status == IPStatus .Success )
{
dosomething;
}