locked
Raise event for javascript/HTML only works for some threads; no dispatcher available? RRS feed

  • Question

  • I want to use raise an event using the standard EventHandler(Of ) from my C# / VB WinRT Winmd class library.  It works fine if Im on a thread that has been passed from javascript but this is kind of pointless and if I try to do on an IO thread or even just on  task threadpool thread, I ever see nothing or worse get a COM exception saying that EventHandler(Of ) cant be marshalled to EventHandler(Of ).

    In Xaml, I am used to using the CoreDispatcher and invoking first to the UI thread, but I dont see how to do this if calling back to javascript from VB?

    Sunday, March 11, 2012 12:25 AM

Answers

All replies

  • Hi Gphb,

    You can use the CoreDispatcher. It is not Xaml specific, but is in Windows.UI.Core and is available to all UI stacks.

    This is demonstrated in Walkthrough: Creating a basic Windows Runtime component in C++ and calling it from JavaScript. The syntax will be different for VB, but the basic idea is the same.

    --Rob

    Monday, March 12, 2012 11:38 PM
    Moderator
  • Thanks.  The key from this article for me was

    Dim coreDispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread..Dispatcher

     coreDispatcher.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,

                                       New Windows.UI.Core.InvokedHandler(Sub()
                                                                              RaiseEvent serviceAvailable(Me, e.ListenUri.ToString)
                                                                          End Sub), Me, Nothing)

    Wednesday, March 14, 2012 1:25 AM