From 2677b0346242512fe72c8050fe2bac7895c1b816 Mon Sep 17 00:00:00 2001 From: artemiusgreat Date: Mon, 24 Jun 2024 10:48:51 -0400 Subject: [PATCH] Dispose --- Libs/ScriptContainer.csproj | 2 +- Libs/ScriptService.cs | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Libs/ScriptContainer.csproj b/Libs/ScriptContainer.csproj index ef984f6..334fca0 100644 --- a/Libs/ScriptContainer.csproj +++ b/Libs/ScriptContainer.csproj @@ -12,7 +12,7 @@ True - 1.3.0 + 1.3.1 artemiusgreat indemos.com http://indemos.com diff --git a/Libs/ScriptService.cs b/Libs/ScriptService.cs index d78ee7a..d094b74 100644 --- a/Libs/ScriptService.cs +++ b/Libs/ScriptService.cs @@ -110,17 +110,11 @@ public async Task SubscribeToSize(ElementReference element, string actio /// public async Task CreateModule(IDictionary options = null) { - try - { - await DisposeAsync(); + await DisposeAsync(); - _serviceInstance = DotNetObjectReference.Create(this); - _scriptModule = await _runtime.InvokeAsync("import", "./_content/ScriptContainer/ScriptControl.razor.js"); - _scriptInstance = await _scriptModule.InvokeAsync("getScriptModule", _serviceInstance, options ?? new Dictionary()); - } - catch (Exception) - { - } + _serviceInstance = DotNetObjectReference.Create(this); + _scriptModule = await _runtime.InvokeAsync("import", "./_content/ScriptContainer/ScriptControl.razor.js"); + _scriptInstance = await _scriptModule.InvokeAsync("getScriptModule", _serviceInstance, options ?? new Dictionary()); return this; } @@ -156,14 +150,16 @@ public virtual Task DisposeAsync() _serviceInstance?.Dispose(); + var response = Task.WhenAll( + _scriptModule is null ? Task.CompletedTask : _scriptModule.DisposeAsync().AsTask(), + _scriptInstance is null ? Task.CompletedTask : _scriptInstance.DisposeAsync().AsTask() + ); + _scriptModule = null; _scriptInstance = null; _serviceInstance = null; - return Task.WhenAll( - _scriptModule is null ? Task.CompletedTask : _scriptModule.DisposeAsync().AsTask(), - _scriptInstance is null ? Task.CompletedTask : _scriptInstance.DisposeAsync().AsTask() - ); + return response; } } }