8000 Async call to update UI in UWP project · Issue #295 · NLua/NLua · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Async call to update UI in UWP project #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
blakepell opened this issue May 17, 2019 · 4 comments
Closed

Async call to update UI in UWP project #295

blakepell opened this issue May 17, 2019 · 4 comments

Comments

@blakepell
Copy link

He's a scenario I have in a UWP app I'm working on (this maybe more of a UWP question and less of an NLua question but I'd like input if any have it). I've written a mud client which is effectively like specialized telnet terminal that can execute commands, batches of commands, scripts, etc. I've exposed a C# object to Lua that allows it to execute sanctioned actions in the client (e.g. write to the terminal, send a command to the network, clear the terminal, etc.). This works mostly.

My problem is, the command runs sync even if I wrap it in an async call. The Lua executes but then doesn't end up updating the UI until the Lua Script is complete so you see everything fly by in a batch. It also hard to time commands since it won't execute, then wait for that previous command to go through to get an updated room variable for instance.

In the old WinForms days I'd have wrapped DoEvents and let Lua call that when it updates the UI (the terminal in my case is updated via binding to a list of strings). I can't seem to figure out how to Lua execute a script but allow updating in the UI in between Lua commands.

Here's an example of something that might be executed (the Sleep(3) is meant to give the previous command time to be sent and return, Sleep being a wrapper to various UWP techniques I've tried that pause).

local room = Cmd:GetVariable("Room")

Cmd:Send("#go The Blood Sea Dock")
Cmd:Send("s")
Cmd:Send("c gate gargoyle")

Cmd:Sleep(3)

room = GetVariable("Room")

if room == "Far Western Wing Of A Forgotten Library" then
...

The "Cmd:Send" command does work, but

@blakepell blakepell changed the title Async call to update UI Async call to update UI in UWP project May 17, 2019
@blakepell
Copy link
Author
blakepell commented May 17, 2019

Here is an example. I get that the second one fires them off async which is why there's no pause.. from C# you'd call an await there (not sure how to do this from a Lua command or if it's possible).

The first one (C# and Lua) included DOES delay for 2 seconds in between commands and doesn't lock the UI up. The second one does not.

// C#
public async void Test()
{
    App.MainPage.Send("say Hello!", Colors.Cyan);
    await Task.Delay(2000);
    App.MainPage.Send("say Goodbye!", Colors.Cyan);
}

-- Lua
Cmd:Test()
// C#
public async void Test()
{
    App.MainPage.Send("say Hello!", Colors.Cyan);
    await Task.Delay(2000);
}

-- Lua, awaiting one of the Cmd:Test() calls is want I suspect I need but not sure if it's possible
Cmd:Test()
Cmd:Test()

What other ways can I approach this?

@viniciusjarina
Copy link
Member

Could you achieve this using .ContinueWith(foo) ?

@blakepell
Copy link
Author

I will test that out.

@SwiTool
Copy link
SwiTool commented Oct 17, 2019

@blakepell did you succeed ? Can you share some code ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0