473,398 Members | 2,335 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,398 software developers and data experts.

threading won't work on function with parameters

Hi all,
I'm trying to use threading model in my web service but addressof does
not work with functions
I'm using VS 2005
my code:

Public Function Start() as Boolean
Dim MyThread As New Thread(AddressOf DoSomething)
MyThread.SetApartmentState(ApartmentState.STA)
MyThread.Start()
End Function

Private Function DoSomething(stuff as string) as string
msgbox stuff
End Function

error is:
Overload resolution failed because no accessible 'New' can be called
with these arguments:
'Public Sub New(start As
System.Threading.ParameterizedThreadStart)': Method 'Private Function
DoSomething(stuff As String) As String' does not have the same
signature as delegate 'Delegate Sub ParameterizedThreadStart(obj As
Object)'.
'Public Sub New(start As System.Threading.ThreadStart)': Method
'Private Function DoSomething(stuff As String) As String' does not
have the same signature as delegate 'Delegate Sub ThreadStart()'.

Why is it trying to compare against the delegate
ParameterizedThreadStart?
If I do it this way it works fine:

Public Function Start() as Boolean
Dim MyThread As New Thread(AddressOf DoSomething)
MyThread.SetApartmentState(ApartmentState.STA)
MyThread.Start()
End Function

Private Sub DoSomething(stuff as object)
dim x as new object
x = stuff
End Sub

but this does not help me out. I need a function not a procedure
any help appreciated. thanks

Nov 14 '07 #1
2 6126
On Nov 15, 3:39 am, esource <darrenp...@shaw.cawrote:
Hi all,
I'm trying to use threading model in my web service but addressof does
not work with functions
I'm using VS 2005
my code:

Public Function Start() as Boolean
Dim MyThread As New Thread(AddressOf DoSomething)
MyThread.SetApartmentState(ApartmentState.STA)
MyThread.Start()
End Function

Private Function DoSomething(stuff as string) as string
msgbox stuff
End Function

error is:
Overload resolution failed because no accessible 'New' can be called
with these arguments:
'Public Sub New(start As
System.Threading.ParameterizedThreadStart)': Method 'Private Function
DoSomething(stuff As String) As String' does not have the same
signature as delegate 'Delegate Sub ParameterizedThreadStart(obj As
Object)'.
'Public Sub New(start As System.Threading.ThreadStart)': Method
'Private Function DoSomething(stuff As String) As String' does not
have the same signature as delegate 'Delegate Sub ThreadStart()'.

Why is it trying to compare against the delegate
ParameterizedThreadStart?
If I do it this way it works fine:

Public Function Start() as Boolean
Dim MyThread As New Thread(AddressOf DoSomething)
MyThread.SetApartmentState(ApartmentState.STA)
MyThread.Start()
End Function

Private Sub DoSomething(stuff as object)
dim x as new object
x = stuff
End Sub

but this does not help me out. I need a function not a procedure
any help appreciated. thanks
Hi,
You can create a function such that instead of returning
something, it just sets the member variable of the class. So, if you
implement this, you will have to check the member variable value after
the thread has completed its execution.
Hope I am clear enough.
Nov 15 '07 #2
You'll need to convert this to vb.net, but this is it in c#

protected void Page_Load(object sender, EventArgs e)
{
Thread t = new System.Threading.Thread(new
ParameterizedThreadStart(DoSomething));
t.Start("Hello");
}
public void DoSomething(object param)
{
string data = (string)param;
System.Diagnostics.Debug.WriteLine(data);
}

"esource" <da********@shaw.cawrote in message
news:11**********************@v3g2000hsg.googlegro ups.com...
Hi all,
I'm trying to use threading model in my web service but addressof does
not work with functions
I'm using VS 2005
my code:

Public Function Start() as Boolean
Dim MyThread As New Thread(AddressOf DoSomething)
MyThread.SetApartmentState(ApartmentState.STA)
MyThread.Start()
End Function

Private Function DoSomething(stuff as string) as string
msgbox stuff
End Function

error is:
Overload resolution failed because no accessible 'New' can be called
with these arguments:
'Public Sub New(start As
System.Threading.ParameterizedThreadStart)': Method 'Private Function
DoSomething(stuff As String) As String' does not have the same
signature as delegate 'Delegate Sub ParameterizedThreadStart(obj As
Object)'.
'Public Sub New(start As System.Threading.ThreadStart)': Method
'Private Function DoSomething(stuff As String) As String' does not
have the same signature as delegate 'Delegate Sub ThreadStart()'.

Why is it trying to compare against the delegate
ParameterizedThreadStart?
If I do it this way it works fine:

Public Function Start() as Boolean
Dim MyThread As New Thread(AddressOf DoSomething)
MyThread.SetApartmentState(ApartmentState.STA)
MyThread.Start()
End Function

Private Sub DoSomething(stuff as object)
dim x as new object
x = stuff
End Sub

but this does not help me out. I need a function not a procedure
any help appreciated. thanks

Nov 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Jorge Godoy | last post by:
Hi! I must have been searching in the wrong places or with the wrong keywords but I couldn't find out how to implement something such as what is done by the threading module on Windows (95, 98...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
15
by: DanielEKFA | last post by:
Hey there :) Just joined the group, looking for a resolution to a problem I and my three groups members are having (we're students, making an FTP-like server/client as an exam project). We're...
4
by: Tuvas | last post by:
I am trying to write a thread that will execute a function every 2 seconds until the program is close, in which case it will stop. I can write the program easy enough to execute the command every 2...
3
by: rollasoc | last post by:
Hi, Having a slight problem with how to pass parameters to functions between threads. I have a form with a progress bar and a description label on it. It has a public function...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
6
by: MPH Computers | last post by:
Hi I am looking for some help on Threading and Critical Sections I have a main thread that controls an event the event handler creates a new thread for carrying out the work because the...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
2
by: esource | last post by:
Hi all, I'm trying to use threading model in my web service but addressof does not work with functions I'm using VS 2005 my code: Public Function Start() as Boolean Dim MyThread As New...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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
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.