Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ah I love threading. It makes programs so much more interesting...</p> <p>So as I started off learning about how to make responsive applications I came across the function: Application.DoEvents()</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx" rel="nofollow noreferrer">(http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx)</a></p> <p>What this does is causes your form to process some of the window events it's receiving. I think that your code could change to include a call after each ping request...</p> <p>i.e. within the on click event handler</p> <pre><code>count = 0; for (int j = 1; j &lt; 255; j++) for (int i = 1; i &lt; 255; i++) { Ping ping = new Ping(); PingReply pingreply = ping.Send(IPAddress.Parse(locip[0] + "." + locip[1] + "." + j + "." + i)); if (pingreply.Status == IPStatus.Success) { status = "o"; repAddress = pingreply.Address.ToString(); ; repRoundtrip = pingreply.RoundtripTime.ToString(); repTTL = pingreply.Options.Ttl.ToString(); repBuffer = pingreply.Buffer.Length.ToString(); string[] lineBuffer = { status, repAddress, repRoundtrip, repTTL, repBuffer }; ipList.Rows.Add(lineBuffer); count += 1; progressBar.Value += 1; } Application.DoEvents(); //but not too often. } </code></pre> <p>Now this was back in the pre dot net days and it's survived till now however, it's not something that you should take lightly. If you click another button on the form it will start off another thread that will attempt to execute and if you're not careful cause thread exceptions on your form. Some developers will tell you don't use this but since your starting off I'd say give it a shot :)</p> <p>I might not use this method depending on the application. Instead what I would do it actually do is to create several processing "trains"; one for each cpu core that the system had. I'd add the ips to be scanned to a queue object and then I would start up 2 to 4 instances of threads (<a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx</a>) each of which taking an item off the queue in turn, process the information (i.e. do the ping logic) and put the result on another queue; and output queue. Every time a train would finish an item for work it would raise an event at the other end of which there would be a handler in the form. Using the Invoke to make thread safe calls (<a href="http://msdn.microsoft.com/en-us/library/ms171728.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms171728.aspx</a>) on my form I would update the UI's information accordingly. </p> <p>Threading is fun dude :) over time you can find that you can use MSMQ to make a system that uses the multicores of other computers to do jobs such as image processing (or something with pa....... ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload