title: ARP ping to Device class
body: <p>I have some problem with my ARP pinging.</p>
  
  <p>First I ping scan to find IP's on network. Then I do an ARP lookup to find MACs (and use a database to find vendors) and Hostnames (if the devices has any). Then I add it all to a Device class in a foreach loop, and display it in my GUI.</p>
  
  <p>This is part of my foreach loop</p>
  
  <pre><code>if (SendARP(intAddress, 0, macAddr, ref macAddrLen) == 0) // ARP Success!
  {
  DoAlotOfStuff(IP,macAddr); // Adds Info to Device class
  }
  </code></pre>
  
  <p>The above code doesn't work. If I add a Threaded sleep it doesn't work either, but if I add a</p>
  
  <pre><code>System.Windows.Forms.MessageBox.Show("");
  </code></pre>
  
  <p>before the DoAlotOfStuff() I will have to press the "OK" button on the messagebox, but the loop works, and the devices gets added succesfully and shown in GUI.</p>
  
  <p>Now what do I do? I think Timers might be a choice, but I am unsure as how to use them. Threaded sleep doesn't work since it pauses the GUI.</p>
  
  <p>SendARP is Pinvoke</p>
  
  <pre><code>[DllImport("iphlpapi.dll", ExactSpelling=true)]
  public static extern int SendARP( 
  int DestIP, int SrcIP, byte[] pMacAddr, ref uint PhyAddrLen);
  </code></pre>
  
  <p>The DoAlotOfStuff function just uses the Device class Setters to set options such as IP,MAC,VENDOR and Hostname</p>
  
  <pre><code>Dns.GetHostEntry(IP).HostName;
  </code></pre>
  
  <p>EDIT: My entire Loop:</p>
  
  <pre><code>        foreach (Device d in Devices)
          {
              IPAddress Destination = IPAddress.Parse(d.GetIP());
  
              byte[] macAddr = new byte[6];
              uint macAddrLen = (uint)macAddr.Length;
  
              int intAddress = BitConverter.ToInt32(Destination.GetAddressBytes(), 0);
  
              if (SendARP(intAddress, 0, macAddr, ref macAddrLen) == 0)
              {
                  d.SetMAC(MacFormat(ByteArrayToString(macAddr)));
  
                  d.SetVendor(CheckVendorList(d.GetIP(), ByteArrayToString(macAddr)));
  
                  d.SetName(FindName(d.GetIP()));
  
                  ADD_TO_LISTVIEW(d.GetAll());
              }
          }
  </code></pre>