Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/TaskDialogLib/TaskDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public class TaskDialog : DependencyObject
Boolean sizeToContent;
Boolean useDefaultIcon;
Boolean verificationChecked;

// This needs to be a class member so that GC doesn't free it prematurely.
TaskDialogCallbackProc callback;

IconHandle iconHandle;
IconHandle footerIconHandle;
Expand Down Expand Up @@ -165,7 +168,7 @@ public class TaskDialog : DependencyObject

#endregion

#region Constructors
#region Constructors and Destructors

/// <summary>
/// Initializes a new instance of the TaskDialog class.
Expand All @@ -178,6 +181,14 @@ public TaskDialog()
useDefaultIcon = true;
}

/// <summary>
/// Cleans up the TaskDialog class.
/// </summary>
~TaskDialog()
{
callback = null;
}

#endregion

#region Events
Expand Down Expand Up @@ -762,7 +773,7 @@ public TaskDialogResult Show()
NativeMethods.TASKDIALOGCONFIG taskDialogConfig = new NativeMethods.TASKDIALOGCONFIG();
taskDialogConfig.cbSize = (UInt32)Marshal.SizeOf(typeof(NativeMethods.TASKDIALOGCONFIG));
taskDialogConfig.hInstance = NativeMethods.GetModuleHandle();
taskDialogConfig.pfCallback = TaskDialogProc;
taskDialogConfig.pfCallback = callback = TaskDialogProc;

Debug.Assert(taskDialogConfig.hInstance != IntPtr.Zero);

Expand Down