vb.net - Visual basic ICMP Pinger? -


i building icmp pinger in visual basic. able determine destination address, time out, size of packets, , how many packets send.

i have small amount of programming knowledge, have suggestions? or more efficient way run program?

here have working far.


option explicit on option infer off

imports system.net.networkinformation imports system.componentmodel

public class form1

private withevents bwping new backgroundworker private pingtarget string private pingsize integer private numofpings integer dim timeout integer  private sub button1_click(byval sender object, byval e eventargs) handles button1.click     ' start pinger     bwping.workerreportsprogress = true     bwping.workersupportscancellation = true     pingtarget = textbox2.text     timeout = combobox4.text      if not bwping.isbusy bwping.runworkerasync()      if combobox3.text & combobox1.text = ""         bwping.cancelasync()         listbox1.items.add("*****!!!!!***** invalid entry *****!!!!!*****")         msgbox(" failing prepare, preparing fail. ", msgboxstyle.exclamation)     elseif combobox3.text = ""         bwping.cancelasync()         listbox1.items.add("*****!!!!!***** invalid entry *****!!!!!*****")         msgbox(" how many troops sending in? ", msgboxstyle.exclamation)     elseif combobox1.text = ""         bwping.cancelasync()         listbox1.items.add("*****!!!!!***** invalid entry *****!!!!!*****")         msgbox(" how strong soldiers? ", msgboxstyle.exclamation)     else : numofpings = cint(combobox3.text)         pingsize = cint(combobox1.text)     end if  end sub  private sub button2_click(byval sender system.object, byval e system.eventargs) handles button2.click     ' cancel pinger     bwping.cancelasync() end sub  private sub button3_click(byval sender object, byval e eventargs) handles button3.click     ' clear     listbox1.items.clear()     combobox1.text = ""     combobox3.text = ""     progressbar1.value = 0 end sub  private sub bwping_dowork(byval sender object, byval e doworkeventargs) handles bwping.dowork     ' ping worker     dim worker backgroundworker = ctype(sender, backgroundworker)     dim packet(pingsize) byte      integer = 0 numofpings - 1         bwping.reportprogress(i + 1)         dim ping new ping         dim reply pingreply = ping.send(pingtarget, timeout)         if combobox3.text & combobox1.text = ""             bwping.cancelasync()         else             listbox1.items.add("you hit " & pingtarget & " in " & reply.roundtriptime.tostring() & " ms " & pingsize & " bytes.")             system.threading.thread.sleep(500)         end if          if worker.cancellationpending exit     next  end sub      private sub bwping_progresschanged(byval sender object, byval e progresschangedeventargs) handles bwping.progresschanged     ' update results     me.progressbar1.value = e.progresspercentage     progressbar1.minimum = 0     progressbar1.maximum = numofpings end sub  private sub bwping_runworkercompleted(byval sender object, byval e runworkercompletedeventargs) handles bwping.runworkercompleted     ' finished     me.listbox1.items.add("*!* battle over, not war *!*")     bwping.cancelasync()  end sub  private sub form1_load(sender object, e eventargs) handles mybase.load     control.checkforillegalcrossthreadcalls = false end sub 

end class