locked
firing and event from a WinRT component's Win32 worker thread and consuming the event it in a xaml/C++ simple GUI event handler

    Question

  • I have a C++ WinRT component that I'm using to interface with the native Win32 API. Suppose I have a long running task where I'm making my old Win32 calls to interface with a legacy DLL for example. I will kick off a thread with ::CreateThread and when I have finished my task I would like to be able to notify my metro gui of the result. What would be the pattern for doing this type of thing using a Metro style C++ app?

     

    Thanks

    Sunday, November 20, 2011 5:55 PM

Answers

All replies

  • Monday, November 21, 2011 9:13 AM
  • Also, I'm wondering is that the best way to do this, I have seen a little info on asyn tasks and I'm wondering if from my WinRT component if I could create a task that does the long running job that the worker thread would have been doing and then have a better integration with Metro so if my app using the WinRT component is suspended, killed, etc. I would not need to worry about managing the lifetime of the thread and likely not have to worry about marshaling the event firing code to the UI thread because I would think it would be running in the same context/apartment as the UI thread. If the WinRT component creates and thread and the application that activates the WinRT component is suspended what happens to this thread that was created with ::CreateThread (Win32)? Is it suspended or does its lifetime need to managed? What is this thread is for a critical task that I want to perform right before my app is suspended or killed by the system. It seems like managing these scenarios using a native thread might not be the best way of doing things.

    Another option, that might be something that look promising is background tasks, I like this option because for what I want to do is global and it work work even better if the user did not have to start my app until they wanted to change their settings if they have configured. I have found the white paper on this and seems like something that is worth investigating and how WinRT components fit with background tasks (can you have long running background tasks or do asyn tasks needs to be scheduled from long running background tasks and can they be scheduled from the WinRT component as well as the Metro app?).

    Thanks

     

    Sunday, November 27, 2011 9:07 PM