I have a win 8 application written in unmanaged c++/cx which has a callback handler. The call back handler posts a notification to a UI thread.
I want to wait on the UI dispatch handler's background task.
I have the following code -
dispatcher->RunAsync(Windows::UI::CoreDispatcherPriority::Normal,lambda);
In the lambda, I update a view model that is bound to my view. I want to wait on this operation and check on the view model. Is it possible in unmanaged c++ ?? It is part of the unit testing that am doing on the app.
I found code references to achieve this in C#. I am not familiar with C++/CX to get this done. I would like comments on ideas to accomplish this. Thank you so much!
regards,
Varsha
Related
I'm using MVVM Light and everything is fine except when launching my Windows Phone 8.1 WinRT app as a Share Target.
When I try to assign MainViewModel viewModel = ServiceLocator.Current.GetInstance<MainViewModel>(); I get an exception for ServiceLocator.Current.
Exception Message: ServiceLocationProvider must be set.
Do I need to do something extra in App.xaml.cs OnShareTargetActivated event to insure the Locator is running?
UPDATE:
A ShareTarget page needs to be thought of as a small extension of your app. It seems that not all of the app's resources are loaded (including app-wide resources in App.xaml). So I just created a new instance of MainViewModel in the share page's constructor, loaded only the things I need for the share to complete, save the information and call ShareOperation.ReportCompleted. This returns the user back to the app that is sharing.
I still haven't found a good solution for getting other resources in my ViewModel, but this works for now.
This indicates that the following line has not been executed:
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
This line will instruct the ServiceLocator class to use the SimpleIoc.Default instance as its ServiceLocator.Current. When you run your app as a Share target, the initialization is slightly different and probably the ViewModelLocator doesn't get initialized. You need to find a good location to perform the initialization before you use the ServiceLocator.
Cheers
Laurent
I am trying to make a generic connectivity class in my Windows Phone 8 app. This class should be used whenever i need to send a POST request to the service.
In a particular use case i need to call the service, display the response and navigate the user away from the current page.
I am able to successfully achieve the first 2 objectives using the connectivity class. This is because the connectivity class is not part of the UI. So is there a way the GetResponseCallBack method can inform the calling method that it has received the response and then i can navigate the user?
Hope i was able to ask my question clearly.
Thanks!
I have managed to find a work-around for now. Not sure if it is the right way to get the response of the async task. But i am sharing it for the benefit for others who may be facing similar issue.
What i have done is, i have defined the GetResponseCallBack as a public method in the class calling the async task method. Later i pass the same GetResponseCallBack as a parameter to the beginGetResponse method in the GetRequestStreamCallBack method.
This way i am able to bring the control flow back to the phoneApplicationPage after the asyncTask executes, thus allowing me to handle some events on the UI thread.
Hope it helps!
I'm developing some corss platform library, and need to execute a action on the UI thread.
Although I know there is a method Dispatcher.RunAsync can execute the action on UI thread, but it is async, and I can't use await/async feature becuase the code is corss platform and I don't want the library is bound to the await/async feature of .net 4.5.
Is there any way to execute the action on UI thread synchronously?
Thanks
A cross-platform library should not depend on a particular UI (e.g., Dispatcher or CoreDispatcher). There's a type that represents an abstract "context": SynchronizationContext; I wrote an MSDN article on the subject a while back.
If it is possible for your library to capture the UI context before it needs to use it, then you can capture SynchronizationContext.Current and later use Send to execute some code on the original context synchronously.
If you execute it from the UI thread - there is no way to do it. From a background thread you might do it for example using an AutoResetEvent that you wait for after calling RunAsync and setting it from the RunAsync callback.
I'm trying to get the CoreDispatcher in C++ on Windows Phone 8 so that I can submit work items to the UI thread Dispatcher so I can update UI elements on the UI thread. However, when I call CoreWindow::GetCurrentForThread(), I get NULL back. In the documentation it states that this is supported on WP8. As long as I'm getting NULL for the current Window, I can't get the current Dispatcher from it; does anyone know how to get the current Dispatcher on WP8?
CoreWindow::GetForCurrentThread() is documented as returning:
The CoreWindow for the currently active thread.
If you call this function from a thread that does not have a CoreWindow (like any non-UI thread), then this function will return nullptr.
Assuming the application has finished initializing and there is a view, you can use the dispatcher from the main view of the application via CoreApplication::MainView. Alternatively, you can pass the Dispatcher^ for the UI thread to the code executing on the non-UI thread so that it has access to it when it needs to invoke back onto the UI thread.
I have used
await CoreApplication.Views.First().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
//your code here
});
I been using the WebService and Operation classes of Flex Framework for a while, and after some ups and downs (more downs than ups, haha) I'm in process of refactoring all its uses with some utility classes/wrappers.
After browsing a little of the code of mx.rpc.soap.Operation I noticed that when you use the method "send" and the web service is not ready then the call is queued to an internal array (pendingInvocations:Array in line 1142). But the funny thing is that the invocations in the queue are never called again.
This is a bug or there is something I'm doing wrong?
I'm considering extending mx.rpc.soap.Operation, overriding "send" and testing if there are invocation queued, calling invokeAllPending (a mx_internal method that pops all the queued invocations) my self.
But the other problem is that that method is mx_internal, so I don't know if Adobe is gonna change it any time soon.
Any advice?
Thanks in advance
It's not a bug. Take a look at the definition for AbstractWebService; it defines a method called unEnqueueCalls (which is right up near the top of the list of awkward method names that I've seen :)). This method loops through all the operations in the webservice and invokes the pending calls for each operation by calling that invokeAllPending method you found.
unEnqueueCalls is itself called from the WebService class, in the wsdlFault and wsdlHandler methods, one of which runs when your WSDL is finished loading.
So, everything is all accounted for; you don't need to override anything.