When awaiting a method it is awaited until the cursor moves
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:1
- Comments:26 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
I didn’t even know. Now it is 😃