Search code examples
c++windows-runtimec++-cxwinrt-async

Windows 8 Store App, Using static class members inside async calls


I am writing an application that does multiple socket operations fairly consistently, and have a event messaging system similar to the javascript paradigm ( eventlistener.on(, ) / eventlistener.emit( ) ). I output some debug information from inside an async call that appends a TextBlock xaml element with the debugging information. When i emit the same event outside an async function, it works fine. I have wrapped my event on/emit calls with mutexes, which I assumed would be good enough to allow me to write to the TextBlock.

To visualize the event process:

[class]->listener->emit(< type>,< data>)->[Dispatcher]->[Listeners(< type>)]->lambda([class],< data>)

I'm not familiar enough with WinRT's async functions and the Windows 8 UI/Metro/Modern ideologies to know if there is a special way for me to append the TextBlock from a thread, or if there is a better way to go about this.

In short, is it possible to append a Textblock from an async function, and if so, do i need to do anything special?


Solution

  • There should be nothing preventing you from updating a TextBlock from an async function as long as the update is on the UI/dispatcher thread. The async function calls on a specific thread usually end on the same thread.