简体   繁体   中英

Main window does not display with .NET 4.7.x / WPF upgrade to .NET to 4.7.x can result in infinite loops

For the benefit of people working with WPF desktop apps with similar problems who get to this issue, here's a summary and workaround when your application window does not appear after the .NET 4.7.x framework upgrade.

Problem

After a basic upgrade of the .NET framework from 4.6.2. to 4.7.x the application main window was never shown and was hang in an infinite loop. The mainwindow.show() function never returned back to the application. The issue is Microsoft .net 4.7.x related but as it is not easy to debug and spot.

Root cause

.Net 4.7 included a new algorithm for allocating space to columns in a Grid declared with '*' in their widths. When an app is compiled for 4.7.x there's a possibility that grid sizing can cause the application to seize up in an infinite loop that can lock and freeze the application.

Originally posted by @SamBent in GitHub/Microsoft/dotnet#604

Solution / Workaround

Set the StarDefinitionsCanExceedAvailableSpace switch to true in the app.config to force using the old algorithm:

<configuration>
        <runtime>
            <AppContextSwitchOverrides value="Switch.System.Windows.Controls.Grid.StarDefinitionsCanExceedAvailableSpace=true" />
        </runtime>
</configuration>

Additional context

https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/runtime/4.7-4.7.1#resizing-a-grid-can-hang

The reported problem above is fixed with this workaround in my WPF desktop app. Hoping this might help others as the debug process can be quite hard. This issue is a .net 4.7.x bug and not solved by Microsoft.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM