0

I just have a simple question, with a Windows Runtime Component (as in a library) that I am making how do I get the window object for the app? CoreWindow::GetForCurrentThread() throws an exception as it seems that the library runs in a different thread then the app. Any one know how to get the app window?

EDIT: GetForCurrentThread is not the problem, it seems that that it only works on the UI thread not a background thread, I would like a way to get at it from a background thread. Is it possible?

Captain Picard
  • 119
  • 4
  • 12

1 Answers1

0

I think Window.Current is what you are looking for.

thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110
  • Still no luck, it seems like the window might not be the problem I get the following error: An unhandled exception of type 'System.Exception' occurred in TestApp.exe WinRT information: The application called an interface that was marshalled for a different thread. – Captain Picard Apr 20 '14 at 22:45
  • Ok, it seems that when stepping through in debug mode no exception is thrown but the app is stuck loading. – Captain Picard Apr 20 '14 at 22:50
  • you need to access this property on the UI thread and not a background thread – thumbmunkeys Apr 20 '14 at 22:50
  • Is there a way to do that in the library? Because the app will have a desktop version so the Windows 8 parts should be hidden from the coder using my library. – Captain Picard Apr 20 '14 at 22:52
  • The only way that comes to my mind, is patching the dispatcher to the lib and then dispatching to the UI thread. Anyways, it is a different question and has nothing to do with the Window – thumbmunkeys Apr 20 '14 at 22:55
  • 1
    I took a look at how Monogame does it, think I am going to do what they did. Thanks for your help. – Captain Picard Apr 20 '14 at 22:57
  • Why not sharing back to the community how did you solve your issue? In any case, the way I'm familiar with, is saving the current window's dispatcher when you are positive you are on the UI thread, and then using a dispatcher. See https://msdn.microsoft.com/en-us/library/hh755833.aspx (look for To add the implementation for GetPrimesUnordered) – Guy Apr 26 '15 at 18:18