c# - How to show only the active computers in a listview? -


i have listview called lvinformation , want add active computers in remote network. take many seconds when response if it's active. want multithreaded, should add computer listview when it's active , refresh listview. don't know how. i'm using following code , that's working takes many seconds...

    system.net.networkinformation.ping objping = new system.net.networkinformation.ping();     objping.sendasync(_remotecomputername, null);      objping.pingcompleted += new pingcompletedeventhandler(objping_pingcompleted);; 

    private void objping_pingcompleted(object sender, pingcompletedeventargs e)     {         domaincomputers.add(_remotecomputername);     } 

domaincomputers property , that's binded twoway.

you may try this:

public partial class mainwindow : window {     public mainwindow()     {         initializecomponent();     }      public observablecollection<string> domaincomputers = new observablecollection<string>();      private void button_click(object sender, routedeventargs e)     {         lvinformation.itemssource = domaincomputers;          list<string> computers = new list<string>();         (int = 1; < 255; i++)         {             computers.add("192.168.9." + i.tostring());         }          foreach (var comp in computers)         {             system.net.networkinformation.ping objping = new system.net.networkinformation.ping();              objping.pingcompleted += new pingcompletedeventhandler(objping_pingcompleted);              objping.sendasync(comp, comp);         }       }      void objping_pingcompleted(object sender, pingcompletedeventargs e)     {         if (e.reply.status == ipstatus.success)             domaincomputers.add(e.userstate string);     } } 

and in xaml

<stackpanel>     <listview name="lvinformation" />     <button click="button_click" content="start" /> </stackpanel> 

but take sample. i'm creatinig far many ping objects. in real life create array of 10 , in pingcompleted event use them ping computer in queue.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -