Activity Stream
48,167 MEMBERS
6815 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24
  1.     
    #21
    Respected Developer
    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;
            
    Ping pingSender = new Ping();
            
    PingOptions options = new PingOptions(64true);
            
    byte[] buffer = new byte[32];

            
    #endregion

            
    public Form1()
            {
                
    InitializeComponent();
                
    updatePingValue(5); //Set defualt to 5


                // no longer using async = no callback needed
                //pingSender.PingCompleted += new PingCompletedEventHandler(PingCallback);

                // wtfbbq??
                /*Ping Options
                Action CallbackAction = new Action(() => pingSender.PingCompleted += new PingCompletedEventHandler(PingCallback));
                CallbackAction.Invoke();*/
            
    }

            private 
    void PingTimes_Scroll(object senderEventArgs e)
            {
                
    updatePingValue(PingTimes.Value);
            }

            private 
    void updatePingValue(int Value)
            {
                
    PingAmount PingTimes.Value;
                
    PingAmountLabel.Text "Pings to send: " PingAmount;
            }

            private 
    void startPing_Click(object senderEventArgs e)
            {
                
    outputBox.Clear();
                
    /*
                 * Start the thread to run the InitiateThreadPinger()
                 */
                //new Thread(InitiateThreadPinger).Start();
                // for fire and forget threads the threadpool is better
                
    ThreadPool.QueueUserWorkItem(InitiateThreadPingeraddressBox.Text);
            }

            public 
    void InitiateThreadPinger(object state)
            {
                
    /*
                 * Loop 1-10 and run a ping on the host
                 */
                
    options.DontFragment true;
                for (
    int i 0<= PingAmounti++)
                {
                    
    // no longer using async = no callback needed
                    
    this.AddCallbackToForm(pingSender.Send((string)state120bufferoptions));
                }
            }

            
    /*public void PingCallback(object sender, PingCompletedEventArgs e)
            {

                if (e.Cancelled)
                {
                    EnableFormElements();
                }
                if (e.Error != null)
                {
                    MessageBox.Show("Ping Failed:" + e.Error.ToString());
                    return;
                }

                PingReply reply = e.Reply;
                AddCallbackToForm(reply);
            }*/

            
    public void AddCallbackToForm(PingReply Reply)
            {
                
    // gets called from the other thread => invoke
                
    this.Invoke((Action)(() =>
                {
                    if (
    Reply == null)
                    {
                        return;
                    }
                    if (
    Reply.Status == IPStatus.Success)
                    {
                        
    outputBox.Text += "Success: " Reply.Address " - " Reply.RoundtripTime "ms";
                        
    outputBox.Text += Environment.NewLine;
                    }
                    else 
                    {
                        
    outputBox.Text += "Failed...";
                        
    outputBox.Text += Environment.NewLine;
                    }
                }));
            }

            public 
    void EnableFormElements()
            {
                
    startPing.Enabled true;
                
    PingTimes.Enabled true;
            }

            public 
    void DisableFormElements()
            {
                
    startPing.Enabled false;
                
    PingTimes.Enabled false;
            }

            private 
    void Form1_Load(object senderEventArgs e)
            {

            }
        }

    ^Works here. See comments.

  2.     
    #22
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Seen comments, ill study what you done, and about ThreadPools

    But are ThreadPools more important for applications that are constantly doing something such as networking tracking and that :/

    Anyways, I know of threadPools but thanks again dood
    Join 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


  3.   Sponsored Links

  4.     
    #23
    ლ(ಠ益ಠლ)
    Website's:
    extremecoderz.com
    Well your example would still do them singularly hyp, and not simultaneously. It would send the work to one thread and repeat it. whereas for x'ing it beforehand would send the math to each thread as fast as it could, and thus not need to wait after every calculation.

  5.     
    #24
    Respected Developer
    ThreadPool = best used in situations where you don't need control over the thread.
    Thread = good for when you need full control over the thread and its execution.

    That's the main difference. Which one you should use depends on what needs to be done.

    Edit @ jay:
    A Ping application should always be sequential. Otherwise you'll have inaccurate results. That's why all ping apps do one ping at a time.

Page 3 of 3 FirstFirst 123

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Application Error Help
    By makfun in forum Technical Help Desk Support
    Replies: 1
    Last Post: 8th Apr 2012, 06:50 PM
  2. Filesonic but which application
    By erikadurane in forum File Host Discussion
    Replies: 4
    Last Post: 1st Jan 2012, 04:43 AM
  3. Replies: 109
    Last Post: 31st Oct 2011, 06:42 PM
  4. RDA Freezing?
    By EL-Warez in forum Server Management
    Replies: 1
    Last Post: 23rd Sep 2011, 01:40 AM
  5. Application Submission on ddl???????
    By power07 in forum Technical Help Desk Support
    Replies: 0
    Last Post: 1st Jan 2011, 01:02 PM

Tags for this Thread

BE SOCIAL