dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.87k stars 1.69k forks source link

Maui crashes when launching a new window in a new thread #5534

Open mattleibow opened 2 years ago

mattleibow commented 2 years ago

Description

Starting a new thread and running:

Application.Current.OpenWindow(new Window(new MultiWindowPage()));

crashes the app. Something about the templates for the WindowRootView not applying.

However, this works:

new Microsoft.UI.Xaml.Window().Activate();

Seems to be our code not WinUI.

Steps to Reproduce

var thread = new Thread(() =>
{
    Microsoft.UI.Xaml.Application.Start(async (p) =>
    {
        var dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
        var syncContext = new Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext(dispatcherQueue);
        SynchronizationContext.SetSynchronizationContext(syncContext);

        Application.Current.OpenWindow(new Window(new MultiWindowPage()));
    });
});

thread.SetApartmentState(ApartmentState.STA);
thread.Start();

Version with bug

Preview 14 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

All

Did you find any workaround?

No response

Relevant log output

No response

VS bug #1786427

mattleibow commented 2 years ago

This is waiting on this feature to be supported by the WASDK. Previously it was supported but then they switched the the new model of a single UI thread.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.