Skip to content

Commit

Permalink
Dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiusgreat committed Jun 24, 2024
1 parent e74053a commit 2677b03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Libs/ScriptContainer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<PropertyGroup>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.3.0</Version>
<Version>1.3.1</Version>
<Authors>artemiusgreat</Authors>
<Copyright>indemos.com</Copyright>
<PackageProjectUrl>http://indemos.com</PackageProjectUrl>
Expand Down
24 changes: 10 additions & 14 deletions Libs/ScriptService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,11 @@ public async Task<string> SubscribeToSize(ElementReference element, string actio
/// <returns></returns>
public async Task<ScriptService> CreateModule(IDictionary<string, dynamic> options = null)
{
try
{
await DisposeAsync();
await DisposeAsync();

_serviceInstance = DotNetObjectReference.Create(this);
_scriptModule = await _runtime.InvokeAsync<IJSObjectReference>("import", "./_content/ScriptContainer/ScriptControl.razor.js");
_scriptInstance = await _scriptModule.InvokeAsync<IJSObjectReference>("getScriptModule", _serviceInstance, options ?? new Dictionary<string, dynamic>());
}
catch (Exception)
{
}
_serviceInstance = DotNetObjectReference.Create(this);
_scriptModule = await _runtime.InvokeAsync<IJSObjectReference>("import", "./_content/ScriptContainer/ScriptControl.razor.js");
_scriptInstance = await _scriptModule.InvokeAsync<IJSObjectReference>("getScriptModule", _serviceInstance, options ?? new Dictionary<string, dynamic>());

return this;
}
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 2677b03

Please sign in to comment.