Results 1 to 10 of 24
Threaded View
-
8th Jul 2010, 09:23 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.com[C#] AutoResetEvent Freezing application!
PHP Code: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;
}
}
}
Hope you can spot my errorlitewarez Reviewed by litewarez on . [C#] AutoResetEvent Freezing application! 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; Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Application Error Help
By makfun in forum Technical Help Desk SupportReplies: 1Last Post: 8th Apr 2012, 06:50 PM -
Filesonic but which application
By erikadurane in forum File Host DiscussionReplies: 4Last Post: 1st Jan 2012, 04:43 AM -
[Hire Me] Freelance Programmer [Rapid Application Development (Windows Application)]
By ?RaJ? in forum Completed TransactionsReplies: 109Last Post: 31st Oct 2011, 06:42 PM -
RDA Freezing?
By EL-Warez in forum Server ManagementReplies: 1Last Post: 23rd Sep 2011, 01:40 AM -
Application Submission on ddl???????
By power07 in forum Technical Help Desk SupportReplies: 0Last Post: 1st Jan 2011, 01:02 PM
themaManager - edit and manage...
Version 4.18 released. Open older version (or...