Skip to content

INavigationAware async methods do not run on UI synchronization context #1306

@elliot-gawthrop

Description

@elliot-gawthrop

Describe the bug

The framework invokes the INavigationAware callbacks through a Task.Run, which causes the callbacks to be run on the thread pool.

Any cross-thread exceptions that do occur within the callback are silently swallowed because the result of the task is discarded.

To Reproduce

Add the following code to an INavgiationAware callback:

if (Thread.CurrentThread != Application.Current.Dispatcher.Thread)
{
    Debugger.Break();
}

Expected behavior

As this interface is intended to be implemented by view models, I expect the callbacks to be run on the UI synchronization context, allowing UI-bound properties to be modified without having to deal without posting the updates to the UI synchronization context manually.

Screenshots

No response

OS version

Windows 10

.NET version

.NET 9

WPF-UI NuGet version

4.0.0-rc.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions