Threading won't work on a function with parameters

Tech-Archive recommends: Fix windows errors by optimizing your registry



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

.



Relevant Pages

  • Re: using Line Input
    ... string in the next chunk. ... Private Sub Class_Initialize ... Public Function ReadDelineatedLine() As String ...
    (microsoft.public.vb.general.discussion)
  • threading wont work on function with parameters
    ... Public Function Startas Boolean ... Private Function DoSomething(stuff as string) as string ... 'Public Sub New(start As ... signature as delegate 'Delegate Sub ParameterizedThreadStart(obj As ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Date & Time
    ... > Private Sub Userform_Initialize ... > ByVal lpWindowName As String) As Long ... > Public Function cbkRoutine(ByVal Window_hWnd As Long, ... > Dim CurrentTime As String ...
    (microsoft.public.excel.newusers)
  • Re: Bind Custom Class to windows form datagrid.
    ... Implementing it in the derived class won't work because ... >> Private mstrFirstName As String ... >> Public Sub New ... >> Public Function AddAs Integer ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • Re: Automatically up date time in a cell
    ... > ByVal lpWindowName As String) As Long ... > Dim CurrentTime As String ... > Sub StartClock() ... > Public Function fncWindowsTimer ...
    (microsoft.public.excel.misc)