Skip to content

Commit

Permalink
Add UnsafeDispose methods to ComServer and WinRtServer
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuelie committed Oct 21, 2024
1 parent 074f943 commit 28da40a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
As such, this needs to be changed before a new release as well.
-->
<PropertyGroup>
<ShmuelieWinRTServerPackageVersion>2.0.0</ShmuelieWinRTServerPackageVersion>
<ShmuelieWinRTServerPackageVersion>2.1.0</ShmuelieWinRTServerPackageVersion>
<IsCommitOnReleaseBranch>false</IsCommitOnReleaseBranch>
</PropertyGroup>

Expand Down
29 changes: 29 additions & 0 deletions src/Shmuelie.WinRTServer/ComServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,35 @@ public bool IsDisposed
private set;
}

/// <summary>
/// Force the server to stop and release all resources.
/// </summary>
/// <remarks>Unlike <see cref="DisposeAsync"/>, <see cref="UnsafeDispose"/> will ignore if any objects are still alive before unregistering class factories.</remarks>
/// <seealso cref="DisposeAsync"/>
public void UnsafeDispose()
{
if (!IsDisposed)
{
try
{
_ = CoSuspendClassObjects();

liveServers.Clear();
lifetimeCheckTimer.Stop();
lifetimeCheckTimer.Dispose();

foreach (var clsid in factories.Keys)
{
_ = UnregisterClassFactory(clsid);
}
}
finally
{
IsDisposed = true;
}
}
}

/// <inheritdoc/>
public async ValueTask DisposeAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Shmuelie.WinRTServer/Shmuelie.WinRTServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>
<IsPackable>true</IsPackable>
<PackageReleaseNotes>Remove support for .NET Standard 2.0 and made package AOT compatible.</PackageReleaseNotes>
<PackageReleaseNotes>Add UnsafeDispose methods to ComServer and WinRtServer.</PackageReleaseNotes>
<IsAotCompatible>True</IsAotCompatible>
<DisableRuntimeMarshalling>True</DisableRuntimeMarshalling>
<RuntimeIdentifiers>win-x64;win-x86;win-arm64;$(RuntimeIdentifiers)</RuntimeIdentifiers>
Expand Down
25 changes: 25 additions & 0 deletions src/Shmuelie.WinRTServer/WinRtServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,31 @@ public void Stop()
return await local.Task.ConfigureAwait(false);
}

/// <summary>
/// Force the server to stop and release all resources.
/// </summary>
/// <remarks>Unlike <see cref="DisposeAsync"/>, <see cref="UnsafeDispose"/> will ignore if any objects are still alive before unregistering activation factories.</remarks>
/// <seealso cref="DisposeAsync"/>
public void UnsafeDispose()
{
if (!IsDisposed)
{
try
{
liveServers.Clear();
lifetimeCheckTimer.Stop();
lifetimeCheckTimer.Dispose();

RoRevokeActivationFactories(registrationCookie);
registrationCookie = (RO_REGISTRATION_COOKIE)0;
}
finally
{
IsDisposed = true;
}
}
}

/// <inheritdoc/>
public async ValueTask DisposeAsync()
{
Expand Down

0 comments on commit 28da40a

Please sign in to comment.