From 661945604198c74d1a6a24a0de6305f77b0afdc7 Mon Sep 17 00:00:00 2001 From: MscrmTools Date: Tue, 31 Oct 2023 10:24:31 +0100 Subject: [PATCH] Added double check to avoid NullReferenceException if no message is passed to WorkAsync method --- XrmToolBox.Extensibility/Worker.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/XrmToolBox.Extensibility/Worker.cs b/XrmToolBox.Extensibility/Worker.cs index df69ebc3..194df6a2 100644 --- a/XrmToolBox.Extensibility/Worker.cs +++ b/XrmToolBox.Extensibility/Worker.cs @@ -75,19 +75,22 @@ public void WorkAsync(WorkAsyncInfo info) _worker.RunWorkerCompleted += (s, e) => { - _infoPanel?.SendToBack(); - - if (info.Host.Controls.Contains(_infoPanel)) + if (_infoPanel != null) { - info.Host.Controls.Remove(_infoPanel); - } + _infoPanel.SendToBack(); - if (_infoPanel?.Tag is Control c && c.Controls.Contains(_infoPanel)) - { - c.Controls.Remove(_infoPanel); - } + if (info?.Host?.Controls.Contains(_infoPanel) ?? false) + { + info.Host.Controls.Remove(_infoPanel); + } + + if (_infoPanel.Tag is Control c && (c?.Controls.Contains(_infoPanel) ?? false)) + { + c.Controls.Remove(_infoPanel); + } - _infoPanel?.Dispose(); + _infoPanel.Dispose(); + } if (info.PostWorkCallBack != null) {