Answered by:
How do I call RfcommDeviceService::FromIdAsync from the UI-Thread?

Question
-
I tried the following, without success. The "result" var is never set
IAsyncOperation<RfcommDeviceService^>^ Foo::getDeviceServiceAsync() { return create_async([this]() { RfcommDeviceService^ result = nullptr; return create_task(m_dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, &result] { create_task(RfcommDeviceService::FromIdAsync(FooDeviceId)) .then([&result](RfcommDeviceService^ deviceService) { result = deviceService; }); }))).then([result]() { return result; }); }); }
Wednesday, July 16, 2014 12:29 AM
Answers
-
No I mean you do a create_task and then run it:
_dispatcher->RunAsync
you need to do that on the next task you create too.
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)- Marked as answer by Anne Jing Monday, August 4, 2014 1:39 AM
Friday, July 25, 2014 2:28 PMModerator
All replies
-
I don't see where you are running the 2nd task you create. I believe that is your problem.
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)Wednesday, July 16, 2014 12:40 PMModerator -
Thanks Jeff for your answer. I still have no clue :/
You mean something like this?:
create_task(RfcommDeviceService::FromIdAsync(FooDeviceId)) .then([&result](RfcommDeviceService^ deviceService) { result = deviceService; }).get();
Wednesday, July 16, 2014 1:07 PM -
No I mean you do a create_task and then run it:
_dispatcher->RunAsync
you need to do that on the next task you create too.
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)- Marked as answer by Anne Jing Monday, August 4, 2014 1:39 AM
Friday, July 25, 2014 2:28 PMModerator