locked
Can we prevent the Dispatcher to try to dispatch events when there is no listener?

    Question

  • From our SQLite3-WinRT component we emit UPDATE/DELETE/INSERT events. Is there a way to prevent firing those event when there is no event listener currently registered?

    Events are defined like this in the component:

    public delegate void ChangeHandler(Platform::Object^ source, ChangeEvent event);
    event ChangeHandler^ Insert;

    and emitted like this:

    // in ctor
    dispatcher = CoreWindow::GetForCurrentThread()->Dispatcher;
    
    
    // When firing an event
    DispatchedHandler^ handler;
    ChangeEvent event;
    event.RowId = rowId;
    event.TableName = ToPlatformString(tableName);
    
    handler = ref new DispatchedHandler([this, event]() {
      Insert(this, event);
    });
    
    dispatcher->RunAsync(CoreDispatcherPriority::Normal, handler);
    

    This might fill up the Windows Message Queue with events although nobody is actually listening to this event.

    Tuesday, December 04, 2012 10:07 AM

All replies

  • Hi,

    Maybe you can try to use thread pool with timer. So that render running times will reduce than Dispatcher.
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465290.aspx

    Or we can use events and semaphore, so that we needn't check them all the time.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 07, 2012 9:19 AM
  • Not sure what you mean Jesse. Our component runs async already. The problem, during a VACUUM procedure of a fairly large DB it will fire thousands of UPDATE/INSERT/DELETE events without a way to queue them for us. The vacuum method just does all this and the dispatcher runs out of space.
    Friday, December 07, 2012 10:53 AM
  • I have a similiar question,

    say I defined an event interface in C++

    public delegate void  event_handler( );

    event event_handler^ on_event;

    How do I know if clients subscribed the event?

    e.g. MyComp.on_event += hanlder;  // how C++ component if event handler list is empty or not?


    rob qqq

    Saturday, December 08, 2012 6:19 AM