run async call from a callback

T

Trapulo

I've seen that if I try to call an invoke (invoke or begininvoke on a
delegate) I always get a notSupportedException. Is there any way I can async
run a sub from a callback target function?

I'm using vb.net with net cf 2.0
 
T

Trapulo

Great, great, great!!

You're great! Thank you, using ThreadPool my application works well, and I
can manager the operation as I need.


thank you a lot!

If this can be usefult to other people, I defined a custom event, and a kind
of wrapper that may execute all subscribed eventhandlers in async way:
Public Custom Event DataReceived As EventHandler(Of DataReceivedEventArgs)

[...]

RaiseEvent(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
For Each item As EventHandler(Of DataReceivedEventArgs) In
_dataReceivedHanlders

Dim p As New Threading.WaitCallback(AddressOf prova)

System.Threading.ThreadPool.QueueUserWorkItem(p, New Object() {item, Me, e})

Next

End RaiseEvent

End Event



Private Sub prova(ByVal state As Object)

Dim a As Object() = DirectCast(state, Object())

Dim eventHandler As EventHandler(Of DataReceivedEventArgs) =
DirectCast(a(0), EventHandler(Of DataReceivedEventArgs))

Dim sender As Object = a(1)

Dim e As DataReceivedEventArgs = DirectCast(a(2), DataReceivedEventArgs)

eventHandler.Invoke(sender, e)

End Sub
 

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