Skip to content

When awaiting a method it is awaited until the cursor moves #306

@timothyparez

Description

@timothyparez

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions