multithreading - C# multi-thread ping -


i'm working on network monitoring application, pings (not known) number of hosts. far have code below. i've made class pinghost function zping , called of timer once every 2 seconds let 2 pings finish, if 1 of them gets timedout. think better solution generate new thread every ping, ping of every host independent.

can give me hint how this?

namespace pinguin {     public partial class form1 : form     {         public form1()         {              initializecomponent();           }          private void timer1_tick(object sender, eventargs e)         {              pinghost caca = new pinghost();             pinghost caca1 = new pinghost();             this.label1.text = caca.zping("89.115.14.160");             this.label2.text = caca1.zping("89.115.14.129");            }      }      public class pinghost     {           public string zping(string dest)         {             application.doevents();             ping sender = new ping();             pingoptions options = new pingoptions();             options.dontfragment = true;              string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";             byte[] buffer = encoding.ascii.getbytes(data);             int timeout = 50;             int failed = 0;             int pingamount = 5;             string stat = "";             pingreply reply = sender.send(dest, timeout, buffer, options);             if (reply.status == ipstatus.success)             {                 stat = "ok";             }             else             {                 stat = "not ok!";             }                return stat;         }     } } 

if use .net 4 can use parallel.invoke.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -