Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

run async call from a callback

147 views
Skip to first unread message

Trapulo

unread,
Mar 20, 2006, 4:33:31 PM3/20/06
to
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


Daniel Moth

unread,
Mar 21, 2006, 9:16:50 AM3/21/06
to
Use the ThreadPool. Invoke/BeginInvoke are only supported on the Control
type (and its descendants). See this example:
http://www.danielmoth.com/Blog/2004/10/invoke-cf-and-full-fx.html

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

"Trapulo" <tra...@noemail.noemail> wrote in message
news:ec1vwXGT...@TK2MSFTNGP09.phx.gbl...

Trapulo

unread,
Mar 21, 2006, 5:11:18 PM3/21/06
to
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

"Daniel Moth" <dmo...@hotmail.com> wrote in message
news:uR9k$IPTGH...@tk2msftngp13.phx.gbl...

0 new messages