c# - Hidden async function -


I am trying to create a library that only has a public function, which gives an NAM. Personal functions, based on my needs, these powers should be asynchronous due to the Android platform. What I want to do, only the public function is used as a non-async function. I know that this can be counter-intuitive, but I have my reasons as far as the function's user is concerned, they had to first run the code as synchronous, and this requirement does not change anymore. That is, it is wrapped in a more efficient library. I do not want them to wait for the law.

Even though I am so far away, but I am struggling with public method:

  public enum DialogResult {Button1 = 1, Button2 = 2, Button3 = 3,} Class MsgBox {Public DialogResult Show (String Title, String Caption, Context Reference) {} Private Async Tasks & lt; DialogResult & gt; ShowAsync (String title, String caption, context reference) BuildAsync for return (title, caption, reference); } Private Tasks & lt; Dialog Result & gt; BuildAsync (string title, string caption, context reference) {var r = new function end source & lt; Dialog Result & gt; (); New Alert Dialogue Builder STPOSitivButton ("yes", (sender, args) => user // yes r sset result (dialogue. Button1);}) .settest button ("no", (sender, args) = & gt; { // nothing. SetResult (DialogResult.Button2);}) .set message (caption) .SetTitle (title). Show (); Return R. Task; }}  

in summary; I want this public function to return to my public dialogue after returning to ShoSync, and myself should not be called in with a wait.

The smallest and best answer "You can not" What are you trying to do, Think about it: Your code requires the use of AOI, which requires execution in the message loop on the UI thread, but the code that calls your code UI Block the thread until your code is complete. This is a logical impossible design.

However, you can use it to force it to work. One option is to offload work from another thread; However, it will not work in your case because you need to run the API that is running on the UI thread. The remaining hack is to run the nested message loop.

There is a very serious problem in running a nested message loop: reentrancy essentially, after you have a nested message loop, the entire application of your customers needs to be handled by reentry, which is why " Code> two events is bad " async


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -