Skip to content

Commit

Permalink
fix: Move DatePicker cleanup from destructor to Unloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jan 26, 2024
1 parent 66d1b78 commit e8ced23
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/Uno.UI/UI/Xaml/Controls/DatePicker/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using DirectUI;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Markup;
using Uno.Disposables;
using Uno.UI.Helpers.WinUI;
using Windows.Foundation;
using Windows.Globalization;
using Windows.Globalization.DateTimeFormatting;
using Windows.UI.Core;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Markup;

namespace Microsoft.UI.Xaml.Controls
{
Expand Down Expand Up @@ -131,8 +129,6 @@ public partial class DatePicker : Control

SerialDisposable m_epFlyoutButtonClickHandler = new SerialDisposable();

// SerialDisposable m_epWindowActivatedHandler = new SerialDisposable();

// See the comment of AllowReactionToSelectionChange method for use of this variable.
bool m_reactionToSelectionChangeAllowed;

Expand Down Expand Up @@ -206,7 +202,16 @@ public DatePicker()

private void DatePicker_Unloaded(object sender, RoutedEventArgs e)
{
// Uno specific: These operations are inside the destructor in WinUI 3, but we need to do them here
// to make sure they happen on the UI thread.

_windowActivatedToken.Disposable = null;

// This will ensure the pending async operation
// completes, closed the open dialog, and doesn't
// try to execute a callback to a DatePicker that
// no longer exists.
m_tpAsyncSelectionInfo?.Cancel();
}

private void DatePicker_Loaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -242,21 +247,6 @@ void OnWindowActivated(object sender, WindowActivatedEventArgs args)
}
#endif

~DatePicker()
{
// This will ensure the pending async operation
// completes, closed the open dialog, and doesn't
// try to execute a callback to a DatePicker that
// no longer exists.
if (m_tpAsyncSelectionInfo != null)
{
/*VERIFYHR*/
m_tpAsyncSelectionInfo.Cancel();
}

// m_epWindowActivatedHandler.Disposable = null;
}

// Initialize the DatePicker
void PrepareState()
{
Expand Down

0 comments on commit e8ced23

Please sign in to comment.