Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2007

Tip: Looking for answers? Try searching our database.

Starting a function on another thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Logan - 22 Aug 2007 14:34 GMT
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.

Signature

Mike Logan

UL-Tomten - 22 Aug 2007 15:50 GMT
> 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).
Steven Cheng[MSFT] - 23 Aug 2007 06:56 GMT
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.
Steven Cheng[MSFT] - 27 Aug 2007 03:21 GMT
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.
--------------------

>Hi Mike,
>
[quoted text clipped - 51 lines]
>
>This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.