Execute Action on UI Thread Synchronously in WinRT - windows-runtime

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.

Related

How can I add debug functions that I can call from Chrome Debugger Console to a Create React App?

I created an app with Create React App.
How can I add global debug functions (e.g. resetDatabase()) that I can call from Chromes Debug Console (or some other way)?
You can attach the function to the global window object, or some namespaced object.
Then in the console you can run it with:
window.resetDatabase();
Here’s a link to a relevant post about accessing the global context through the componentWillMount callback.
How to declare a global variable in React?
Refer this site -:
IT gives you the complete guide for that or if you face any issue feel free to ask
https://developers.google.com/web/tools/chrome-devtools/console/

Achieve Do after and before using ES6 Proxy

I've a View and Utility classes and wanted to hook-in the Utility method once View's job is done. So wanted to call the utility method (to add behavior to the view) once View's render call is done.
Using ES6 Proxy API, Is there a way to execute a method before / after executing the main method ? (aka method interceptions)
Similar to YUI3 Do API.
http://yuilibrary.com/yui/docs/api/classes/Do.html
Yes there is a way. Actually I'm trying to build the same thing and as long as you use a synchronous context I already got it working. Have a look at the code examples in the issue I created for my problem: stack overflow when returning an ES6 proxy through a promise
What you need to do to intercept the call is to use the ES6 proxy to get notified of the get-call that takes place to retrieve the function before the method is actually called.
In my example you can see that you get all the information about the call like what method was called with which parameters and also who called it and on which target it was originally called.

win 8 app call back handler - waiting on a runasync operation C++

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

CoreWindow::GetCurrentForThread() always NULL

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
});

Flex WebService invokeAllPending never called

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.