By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,578 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

Passing parameter to a Threaded function?

P: n/a
Hello everyone,
I am developping an application, I create a thread for the application
because it is about to download a large file, and wanted it to do it inside
of a thread... Now, the function I need the thread to call has a
parameter...
How do I call a function with the addressof(..) with a parameter value?

for example:
public function processData(byval data as arraylist) as boolean....
....
end function

dim thrd as new thread(addressof(processData))
thrd.start( )

I have not be able to find a way to pass a value to data...

Please help...
SJ


Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Sam Learner" <Sa****@easynetsoft.dynu.com> schrieb:
How do I call a function with the addressof(..) with a parameter value?

for example:
public function processData(byval data as arraylist) as boolean....
...
end function

dim thrd as new thread(addressof(processData))
thrd.start( )


<URL:http://groups.google.de/groups?selm=c61hee%246tag3%241%40ID-208219.news.uni-berlin.de>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #2

P: n/a
2 articles

http://www.devx.com/dotnet/Article/11358/

http://msdn.microsoft.com/library/de...procedures.asp

Sam Learner wrote:
Hello everyone,
I am developping an application, I create a thread for the application
because it is about to download a large file, and wanted it to do it
inside of a thread... Now, the function I need the thread to call has
a parameter...
How do I call a function with the addressof(..) with a parameter
value?
for example:
public function processData(byval data as arraylist) as boolean....
...
end function

dim thrd as new thread(addressof(processData))
thrd.start( )

I have not be able to find a way to pass a value to data...

Please help...
SJ

Nov 21 '05 #3

P: n/a
Try this. You have to delcate the function you wand called at the beginning
of the class as a delegate.

Then you have to create a class inside the main class which contains the
variables you need to send into the function. Also create a function with no
paramaters that will call the delegate

Then you create the actual function that the thread will call. it's
paramaters must match the Delegate.

Then create an instance of the class in the calling function. set the
variables and the address of the function being called in the class.

Private Delegate Sub DeleteDelegate(ByVal MessageAs String) 'Paramaters must
match the function being called

Private Class DeleteArgs

Public cMessage As String

Public StartDelegate As DeleteDelegate 'instance of function to call

Public Sub DeleteFiles()

StartDelegate(cMessage)

End Sub

End Class

Public Sub DeleteFiles(ByVal pMessage As String)

msgbox(pMessage)
End Sub

public sub FunctionToLaunchThreads()

Dim ca As DeleteArgs 'instance of class

Dim t As Thread

ca = New DeleteArgs

ca.cMessage = "Testing the threading function")

ca.StartDelegate = AddressOf DelFiles 'set the function to call

t = New Thread(AddressOf ca.DeleteFiles) 'set the thred to the function of
the class

t.Name = "Thread Delete Old Files"

t.ApartmentState = ApartmentState.MTA

t.Start()

end sub

Brad Shook

"Eric Sabine" <mopar41@mail_after_hot_not_before.com> wrote in message
news:eV****************@TK2MSFTNGP12.phx.gbl...
2 articles

http://www.devx.com/dotnet/Article/11358/

http://msdn.microsoft.com/library/de...procedures.asp
Sam Learner wrote:
Hello everyone,
I am developping an application, I create a thread for the application
because it is about to download a large file, and wanted it to do it
inside of a thread... Now, the function I need the thread to call has
a parameter...
How do I call a function with the addressof(..) with a parameter
value?
for example:
public function processData(byval data as arraylist) as boolean....
...
end function

dim thrd as new thread(addressof(processData))
thrd.start( )

I have not be able to find a way to pass a value to data...

Please help...
SJ


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.