question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When awaiting a method it is awaited until the cursor moves

See original GitHub issue

I am probably just doing it the wrong way but the idea is that I have one (or more) buttons which when pressed/clicked load some data and display that data in a ListBox.

When I click the button the first time I can see the first WriteLine and then the LoadItemsAsync method is awaited.

If I don’t do anything it will just await forever.
When I click the button again or move focus to the next control
the awaited method completes and the next WriteLine is executed.

Update: If I move the mouse the awaited method also completes

I have tried without MainLoop.Invoke as well.
I’m guessing I am just handling this the wrong way.

Any suggestions?

button.Clicked += async () =>
{
    Application.MainLoop.Invoke (async () => {
            
        //When the button is 'clicked' the following is executed
        Debug.WriteLine($"Clicked the button");
        var items = await LoadItemsAsync();

        //However the following line is not executed
        //until the button is clicked again or
        //until the cursor is moved to the next view/control 
        Debug.WriteLine($"Got {items.Count} items)");                                                     
        itemsList.SetSource(items);

        //Without calling this the UI is not updated
        this.LayoutSubviews();                    
    });
};

System: Ubuntu 19.10

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:26 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
migueldeicazacommented, Nov 25, 2019

In your case, you are adding a idle handler in response to the click to run on the UI thread - but you are already on the main thread.

You do not need that level of indirection.

The patch shown before that does Send + MainLoop is likely wrong, as this would invoke a method that is expected to run on the UI from the background

1reaction
BDispcommented, Nov 25, 2019

I didn’t even know. Now it is 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

When awaiting a method it is awaited until the cursor moves
When a key is pressed or the mouse is moved is like the caller code is wakeup and request for the awaiting called...
Read more >
Async method await keyword doesn't suspend to calling ...
The await operator suspends execution until the work of the WaitAsync() (Delay 10 seconds) method is complete.
Read more >
Understanding Control Flow with Async and Await in C# | ...
We know now that await doesn't block - it frees up the calling thread. But how does this non-blocking behavior manifest itself to...
Read more >
Async/Await — What Happens Under The Hood
When the OS got all the data, a callback is evoked and the code execution will continue and the text will be displayed....
Read more >
await operator - asynchronously wait for a task to complete
The await operator suspends evaluation of the enclosing async method until the asynchronous operation represented by its operand completes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found