473,769 Members | 8,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(byv al data as arraylist) as boolean....
....
end function

dim thrd as new thread(addresso f(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 2031
"Sam Learner" <Sa****@easynet soft.dynu.com> schrieb:
How do I call a function with the addressof(..) with a parameter value?

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

dim thrd as new thread(addresso f(processData))
thrd.start( )


<URL:http://groups.google.d e/groups?selm=c61 hee%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(byv al data as arraylist) as boolean....
...
end function

dim thrd as new thread(addresso f(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(c Message)

End Sub

End Class

Public Sub DeleteFiles(ByV al pMessage As String)

msgbox(pMessage )
End Sub

public sub FunctionToLaunc hThreads()

Dim ca As DeleteArgs 'instance of class

Dim t As Thread

ca = New DeleteArgs

ca.cMessage = "Testing the threading function")

ca.StartDelegat e = AddressOf DelFiles 'set the function to call

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

t.Name = "Thread Delete Old Files"

t.ApartmentStat e = ApartmentState. MTA

t.Start()

end sub

Brad Shook

"Eric Sabine" <mopar41@mail_a fter_hot_not_be fore.com> wrote in message
news:eV******** ********@TK2MSF TNGP12.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(byv al data as arraylist) as boolean....
...
end function

dim thrd as new thread(addresso f(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
7664
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 indicate: a) That I don't know enough b) Passing arguments by ref is bad
2
14021
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 run using its own data. I've looked at SetData and GetData but these seem only to be available once the thread is running. The ThreadStart delegate won't allow me to use a function with parameters.. so I can see now way that a parent thread can...
11
8128
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 number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
3
2621
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 wrapper function. I would prefer to be able to pass the member function as a void* to the static wrapper but I suspect this may not even be possible. Another solution would be option 2 below but I can't figure out the syntax to call obj->*pFn(). ...
2
1574
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 little confusion. ***************CODE BEGINS************************************ class MyFrame1(wx.Frame): def __init__(self, *args, **kwds): ..... ..... def OnEdit(self, event):
10
3933
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication eventname string source string ID string
0
1255
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 (I need help in passing this)) Postev.postEvent(auth(), "Test", "1234567", tdt, parameter()) For the first parameter authentication I have: Private Function auth() As ws.Authentication
7
3307
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 object is a reference type? my code is not proving that. I have a web project i created from a web service that is my object: public class ExcelService : SoapHttpClientProtocol {
12
2594
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 by value temporaries are created?(I'm not touching yet the cases where standard allows optimizations from the side of implementations to avoid copying) If so, please quote part of the standard that says that. Assuming it is true, I can imagine two...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.