Starting a function on another thread

G

Guest

My environment: VS 2k5 Team Software developer SP1, VB.Net, Web Service

I have a web service. I also have another class file. I am trying to call
a web service operation from within my private class file on another thread.

In my class file I have this

Private Sub MyPrivateSub()

Dim serv1 as MyWebServiceClass

Dim t1 as New System.Threading.Thread( _
New System.Threading.ThreadStart( _
AddressOf serv1.Operation1))

End Sub

I can't get past that line to create the thread. The error is

Method 'Public Function Operation1(byval Param1 as Object) as ReturnObject'
doesn't have the same signature as delegate 'Delegate Sub ThreadStart()'

The web serivce class has a parameter-less constructor.

Thanks for any help.
 
U

UL-Tomten

Method 'Public Function Operation1(byval Param1 as Object) as ReturnObject'
doesn't have the same signature as delegate 'Delegate Sub ThreadStart()'

The error message isn't kidding. The signatures really are different.
Just look:

Sub ThreadStart()
vs
Function Operation1(byval Param1 as Object) as ReturnObject

You have to match the signature to be able to use the method as a
ThreadStart. The reason you can't return anything in the method is
that there's no control over the receiving end, so the returned object
would wind up nowhere.

If you can live with using the managed thread pool, you can use
delegates instead, which will give you easier access to function-like
behavior. Otherwise, the other delegate usable in Thread.Start() might
be of interest (but that one doesn't return anything either).
 
S

Steven Cheng[MSFT]

Hi Mike,

Does Tomten's suggestion help you on this problem? For creating custom
thread which take a ThreadStart function, you need to define a function
with the required signature of "ThreadStart delegate"(it is a void
function):

#ThreadStart Delegate
http://msdn2.microsoft.com/en-us/library/system.threading.threadstart.aspx

or if you want your thread function be able to accept some additional
parameters, you can choose the new "ParameterizedThreadStart delegate":

#ParameterizedThreadStart Delegate
http://msdn2.microsoft.com/en-us/library/system.threading.parameterizedthrea
dstart.aspx

BTW, for webservice client proxy, you can also use
proxy.BeginXXXX/proxy.EndXXX methods or the new proxy.XXXXAsync pattern
to do asynchronous webservice call, these calles are also executed on
another threadpool thread.

#New Event-Based Model For Asynchronous WebMethod Calls
http://quickstarts.asp.net/QuickStartv20/webservices/doc/RADAsync.aspx

Does this also help for your case?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Mike,

Any progress on this issue or do you have any other questions? If so,
please don't hesitate to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top