473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Passing parameter to a Threaded function?

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
3 2002
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
2
by: Dirc | last post by:
We are building a threaded application which reacts to an event and starts the required processing on a new thread. However, we are finding it difficult finding a way of getting the function to...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
3
by: dice | last post by:
Hi, In order to use an external api call that requires a function pointer I am currently creating static wrappers to call my objects functions. I want to re-jig this so I only need 1 static...
2
by: diffuser78 | last post by:
I wrote a small app in wxPython using wxGlade as designer tool. wxGlade brings and writes a lot of code by itself and thats where my confusion started. Its about parameter passing. Here is my...
10
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication...
0
by: amazon | last post by:
I have web service that acceping following parameters.. postev.PostEvent(authentication as ws.authentication, name as string,id as string, exdate as date, parameter() as ws.nameparametervaluepair...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.