feat: fix memory leakage.

This commit is contained in:
rabbitism
2024-01-22 19:00:12 +08:00
parent f0ec32c870
commit 0a3f7dbf5f
4 changed files with 25 additions and 10 deletions

View File

@@ -10,8 +10,6 @@ public class DialogControl: ContentControl
{
public const string PART_CloseButton = "PART_CloseButton";
private Button? _closeButton;
public event EventHandler<object?> OnClose;
@@ -38,17 +36,22 @@ public class DialogControl: ContentControl
public Task<T> ShowAsync<T>()
{
var tcs = new TaskCompletionSource<T>();
this.OnClose+= (sender, args) =>
void OnCloseHandler(object sender, object? args)
{
if (args is T result)
{
tcs.SetResult(result);
OnClose-= OnCloseHandler;
}
else
{
tcs.SetResult(default);
tcs.SetResult(default(T));
OnClose-= OnCloseHandler;
}
};
}
this.OnClose += OnCloseHandler;
return tcs.Task;
}