ChrisB.
Think of "AddressOf" as New for Delegates, you only need to use it when you
want to create a new delegate, not when you already have an existing
Delegate.
Define your function as taking a ThreadStart parameter, when you call your
function use AddressOf, when you create the Thread itself you do not need
AddressOf as you already have a Delegate.
Something like:
Imports System.Threading
Private Sub Worker()
' do work here...
End Sub
Private Sub MoreWork()
' do more work here...
End Sub
Private Sub SubmitWork(ByVal worker As ThreadStart)
Dim theThread As New Thread(worker)
theThread.Start()
End Sub
Public Sub Main()
SubmitWork(AddressOf Worker)
SubmitWork(AddressOf MoreWork)
End Sub
Notice that when we call SubmitWork we use AddressOf to create a new
Delegate. Then when we create a new Thread within SubmitWork, we simply pass
that Delegate directly to the constructor.
Hope this helps
Jay
"ChrisB" <Ch****@discussions.microsoft.com> wrote in message
news:D2**********************************@microsof t.com...
So.. any help here? Anyone else got delegates working as a parameter for a
function to be used with an AddressOf operator?
"ChrisB" wrote:
I tried using delegates but I don't know how. I tried something like
this:
delegate function fpMyfunc()
(I also tried delegate sub fpMyfunc())
Then:
function( thesub as fpMyfunc )
dim t as new system.threading.thread( _
new system.threading.threadstart( Addressof thesub ))
But this did not work. VB.Net complained about the "thesub" after the
Addressof.. saying that I do not need ()'s after the sub name, as if it
did
not recognize "thesub" as being a subroutine.
"Ron Bremmers" wrote:
> Use delegates. Delegates are the equivalent of function pointers in
> .NET.
>
>
>
> Regards,
>
>
>
> Ron
>
>
>
> "ChrisB" <Ch****@discussions.microsoft.com> wrote in message
> news:87**********************************@microsof t.com...
> > Coming from a C/C++ background, how would I pass a function pointer
> > to a
> > function? I want to write a function that handles certain thread
> > spawning.
> > Here's what I'm trying to invision:
> >
> > function( thesub as <functionptr?> )
> > dim t as new system.threading.thread( _
> > new system.threading.threadstart( Addressof thesub ))
> > ...
> >
> > How can I get something like that going in VB.Net?
>
>
>