简体   繁体   中英

Exception 'System.ExecutionEngineException' occurred in DirectWriteForwarder.dll

I am building a WPF app on .NET Core 3.1. Basically, the setup of the app is a main screen with a tab control with two tabs. Each tab has a thread running in the background to pull data from different devices.

In each tab I have a frame that holds a page so that each page opens and closes every time the tab is changed to reduce load on the UI thread.

<TabControl SelectedItem="{Binding SelectedMainTab, Mode=TwoWay}">

    <!-- SCAN TAB -->
    <TabItem x:Name="ScanTab">
        <TabItem.Header>
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Width="100" Height="40" HorizontalAlignment="Center">
                <TextBlock Style="{StaticResource TabTextBlock}" Text="Scan" VerticalAlignment="Center" Margin="5,0"/>
            </StackPanel>
        </TabItem.Header>
        <Frame Source="ScanView.xaml"/>
    </TabItem>

    <!-- VALIDATION TAB -->
    <TabItem x:Name="ValidationTab">
        <TabItem.Header>
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Width="150" Height="40" HorizontalAlignment="Center">
                <TextBlock Style="{StaticResource TabTextBlock}" Text="Validation" VerticalAlignment="Center" Margin="5,0"/>
            </StackPanel>
        </TabItem.Header>
        <Frame Source="ValidationView.xaml"/>
    </TabItem>
</TabControl>

Basically, when a page unloads, I have it stop the thread that was running, polling the device status. Simple enough. But what happens is when I load up the app and begin switching back and forth between the tabs. The UI freezes up and then it crashes with An Exception 'System.ExecutionEngineException' occurred in DirectWriteForwarder.dll

There is no line number that this occurs on and from a bit of googling I can't seem to find much about what this DLL is except it is part of .net. Any assistance would be greatly appreciated!

EDIT

Upon trying to replicate the error I also get it to crash with System.Collections.dll being the location the exception occurs. Same exception though.

So I might have an answer to my own question. I did not fully determine the cause of the issue. But figured out it was something to do with garbage collection and probably how I was disposing of one thread when switching tabs.

Ultimately, on the unloading event of the page that is opened by the tab, I placed the "shutdown" functionalities inside a thread with IsBackground = true. This will allow them to dispose of themselves without some properties they use from the page being disposed of.

This has seemed to fix my issue since I do not receive that crash anymore.

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