Skip to content

Commit

Permalink
Attempt to fix crash on startup that sometimes happens on some systems
Browse files Browse the repository at this point in the history
  • Loading branch information
astenlund committed Oct 20, 2020
1 parent f1ba693 commit c64b2c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Width="555" Height="370"
MinWidth="555" MinHeight="370"
Closing="Window_Closing"
Loaded="MainWindow_Loaded"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Window.Resources>
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
Expand Down
12 changes: 5 additions & 7 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public MainWindow()
InitializeComponent();
}

protected override void OnSourceInitialized(EventArgs e)
private void Window_Closing(object sender, CancelEventArgs e)
{
base.OnSourceInitialized(e);
((ISimConnectMessageHandler) DataContext).Dispose();
}

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
HwndSource hwndSource = (HwndSource) PresentationSource.FromVisual(this)!;
hwndSource.AddHook(WndProc);
((ISimConnectMessageHandler) DataContext).WindowHandle = hwndSource.Handle;
Expand All @@ -35,10 +38,5 @@ private IntPtr WndProc(IntPtr hWnd, int iMsg, IntPtr hWParam, IntPtr hLParam, re

return IntPtr.Zero;
}

private void Window_Closing(object sender, CancelEventArgs e)
{
((ISimConnectMessageHandler) DataContext).Dispose();
}
}
}

0 comments on commit c64b2c5

Please sign in to comment.