@@ -23,6 +23,13 @@ public abstract class RxBimApplication : IExtensionApplication
2323 /// via Addin Manager.
2424 /// </summary>
2525 protected virtual bool RunInSeparatedContext => false;
26+
27+ /// <summary>
28+ /// Reuses the context for the application's DLL directory until AutoCAD exits.
29+ /// Applies only when <see cref="RunInSeparatedContext"/> is enabled.
30+ /// Enable this setting for the application's commands as well to share the same context.
31+ /// </summary>
32+ protected virtual bool ReuseSeparatedContext => false;
2633#endif
2734
2835 /// <inheritdoc />
@@ -34,6 +41,12 @@ public void Initialize()
3441 var type = GetType();
3542 if (!PluginContext.IsCurrentContextRxBim(type))
3643 {
44+ if (ReuseSeparatedContext)
45+ {
46+ InitializeInReusedContext(type);
47+ return;
48+ }
49+
3750 var appInstance = PluginContext.CreateInstanceInNewContext(type);
3851 if (appInstance is IExtensionApplication application)
3952 {
@@ -67,6 +80,26 @@ public void Terminate()
6780 /// </summary>
6881 protected virtual bool CanBeStarted() => true;
6982
83+ #if NETCOREAPP
84+ private void InitializeInReusedContext(Type type)
85+ {
86+ IExtensionApplication application;
87+
88+ try
89+ {
90+ application = (IExtensionApplication)PluginContext.CreateInstanceInReusedContext(type);
91+ }
92+ catch (Exception exception)
93+ {
94+ // Report loading failures without initializing in the original context.
95+ Application.ShowAlertDialog($"Error: {exception}");
96+ return;
97+ }
98+
99+ application.Initialize();
100+ }
101+ #endif
102+
70103 private void ApplicationOnIdle(object? sender, EventArgs e)
71104 {
72105 Application.Idle -= ApplicationOnIdle;
0 commit comments