Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is more safe to do manual disposing internally. #1167

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/RhinoInside.Revit.External/UI/UIHostApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@ namespace RhinoInside.Revit.External.UI
using Autodesk.Revit.ApplicationServices;
using External.DB.Extensions;

public abstract class UIHostApplication : IDisposable
public abstract class UIHostApplication
{
protected internal UIHostApplication(bool disposable) => Disposable = disposable;

#region IDisposable
#pragma warning disable CA1063 // Implement IDisposable Correctly
readonly bool Disposable;
protected abstract void Dispose(bool disposing);
void IDisposable.Dispose()
{
if (!Disposable) return;

Dispose(disposing: true);
GC.SuppressFinalize(this);
}
#pragma warning restore CA1063 // Implement IDisposable Correctly
#endregion

Expand All @@ -37,7 +30,17 @@ void IDisposable.Dispose()
public abstract UIDocument ActiveUIDocument { get; set; }

#region Runtime
internal static UIHostApplication Current;
private static UIHostApplication _Current;
internal static UIHostApplication Current
{
get => _Current;
set
{
if (_Current == value) return;
_Current?.Dispose(true);
_Current = value;
}
}

internal static bool StartUp(UIControlledApplication app)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ public UIHostApplicationConstrained(UIControlledApplication app, bool disposable
{
_app = app;

if (!disposable)
{
#if REVIT_2023
_app.SelectionChanged += SelectionChangedHandler;
_app.SelectionChanged += SelectionChangedHandler;
#endif
}
}
protected override void Dispose(bool disposing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override void Dispose(bool disposing)
_app.SelectionChanged -= SelectionChangedHandler;
#endif
_app.ViewActivated -= UpdateOpenViewsList;
_app.Dispose();
//_app.Dispose();
}

_app = null;
Expand Down
Loading