3 Replies - 1618 Views - Last Post: 08 December 2009 - 11:35 AM Rate Topic: -----

#1 Matty919  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 83
  • Joined: 10-May 09

Multithreading

Posted 02 December 2009 - 03:07 PM

I want to apply multithreading in my program but I am finding it rather confusing. Pinging takes a while so I wanted to start a new thread for every ping attempt to not freeze the application (eventually it will be a form). I thought I could just but I get the error: Error 1 'AddressOf' operand must be the name of a method (without parentheses).

Imports System.Threading
Module Module1

	Sub Main()
		Dim IP() As String = {"127.0.0.1", "192.168.1.254"}

		Dim intcounter As Integer

		For intcounter = 0 To IP.GetUpperBound(0)
			Dim Thread As New Thread(AddressOf ping(intcounter))
			Thread.Start()
		Next

		Console.ReadKey()
	End Sub
	Sub ping(ByVal strIP As String)
		If My.Computer.Network.Ping(strIP) = True Then
			Console.WriteLine("{0} is alive.", strIP)
		Else
			Console.WriteLine("{0} is dead.", strIP)
		End If
	End Sub
End Module


I found this: http://www.pberblog....g-in-VBnet.aspx and downloaded the source but can't seem to understand it, seems quite complex.

Is This A Good Question/Topic? 0
  • +

Replies To: Multithreading

#2 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: Multithreading

Posted 02 December 2009 - 03:09 PM

look into the backgroundworker. System.Threading is the old way to multithreading.

http://msdn.microsof...oundworker.aspx
Was This Post Helpful? 0
  • +
  • -

#3 n0c0d3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 21-December 08

Re: Multithreading

Posted 03 December 2009 - 02:30 PM

I recently found a simple basic explanation how to get a backgroundworker to work:
http://vbnotebookfor...worker-in-vbnet
I works fine for me.

Good luck,
Bart
Was This Post Helpful? 1
  • +
  • -

#4 some_kid  Icon User is offline

  • New D.I.C Head

Reputation: 10
  • View blog
  • Posts: 43
  • Joined: 26-May 09

Re: Multithreading

Posted 08 December 2009 - 11:35 AM

You need to change the thread setup to:
				Dim Thread As New Thread(AddressOf ping)
				Thread.Start(IP(intcounter))

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1