imports system.threading
public class form1
delegate sub addlistitem(byval ipstring as string, byval scanport as integer)
public mydelegate as addlistitem
public openportcount as integer = 0
private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
mydelegate = new addlistitem(addressof addlistitemmethod)
end sub
private sub start_button_click(byval sender as system.object, byval e as system.eventargs) handles start_button.click
dim mythread as thread
mythread = new thread(new threadstart(addressof threadfunction))
mythread.start()
end sub
private sub threadfunction()
dim mythread as thread
mythread = new thread(new threadstart(addressof doscanthread))
mythread.start()
end sub 'threadfunction
private sub doscanthread()
dim mythreadclassobject as new scanthreadclass(me)
mythreadclassobject.run()
end sub
public sub addlistitemmethod(byval ipstring as string, byval scanport as integer)
listview_result.items.add(ipstring, openportcount) 'scanip.tostring(), 0)
listview_result.items(openportcount).subitems.add(scanport.tostring())
openportcount += 1
end sub 'addlistitemmethod
end class
public class scanthreadclass
private myformcontrol1 as form1
public sub new(byval myform as form1)
myformcontrol1 = myform
end sub 'new
public sub run()
myformcontrol1.invoke(myformcontrol1.mydelegate, new object() {11, 123})
end sub
end class
主要注意的就是invoke的调用和delegate的定义。
