PHP:
using System;
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.Net;
using System.Net.NetworkInformation;
using System.Threading;
namespace SimplePinger
{
public partial class Form1 : Form
{
#region Variables
int PingAmount = 5;
AutoResetEvent Waiter = new AutoResetEvent(false);
Ping pingSender = new Ping();
PingOptions options = new PingOptions(64, true);
#endregion
public Form1()
{
InitializeComponent();
updatePingValue(5); //Set defualt to 5
}
private void PingTimes_Scroll(object sender, EventArgs e)
{
updatePingValue(PingTimes.Value);
}
private void updatePingValue(int Value)
{
PingAmount = PingTimes.Value;
PingAmountLabel.Text = "Pings to send: " + PingAmount;
}
private void startPing_Click(object sender, EventArgs e)
{
DisableFormElements();
outputBox.Clear();
options.DontFragment = true;
pingSender.PingCompleted += new PingCompletedEventHandler(PingCallback);
//Create 32 byts to send
byte[] buffer = Encoding.ASCII.GetBytes(" ");
int i;
for (i = 0; i < PingAmount; i++)
{
//Here i want to run this 5 times but without the app freezing :(
pingSender.SendAsync(addressBox.Text, 120, buffer, options);
}
Waiter.WaitOne();
EnableFormElements();
}
public void PingCallback(object sender, PingCompletedEventArgs e)
{
if (e.Cancelled)
{
EnableFormElements();
}
if (e.Error != null)
{
MessageBox.Show("Ping Failed:" + e.Error.ToString());
// Let the main thread resume.
((AutoResetEvent)e.UserState).Set();
}
PingReply reply = e.Reply;
Waiter.Set();
AddCallbackToForm(reply);
}
public void AddCallbackToForm(PingReply Reply)
{
if (Reply == null)
{
return;
}
if (Reply.Status == IPStatus.Success)
{
outputBox.Text += "Success: " + Reply.Address + " - " + Reply.RoundtripTime + "ms";
}
else
{
outputBox.Text += "Failed...";
}
}
public void EnableFormElements()
{
startPing.Enabled = true;
PingTimes.Enabled = true;
}
public void DisableFormElements()
{
startPing.Enabled = false;
PingTimes.Enabled = false;
}
}
}
here is the Form Class, seems to be freezing / hanging for a while and im sure its something Very stupid but every tutorial that i read shows me that im doing it right
Hope you can spot my error