mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-04 00:35:40 +08:00
忘记改啥了*1
This commit is contained in:
53
NodeFlow/Tool/FlowLibraryLoader.cs
Normal file
53
NodeFlow/Tool/FlowLibraryLoader.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Tool
|
||||
{
|
||||
/// <summary>
|
||||
/// 管理加载在流程的程序集
|
||||
/// </summary>
|
||||
public class FlowLibraryLoader : AssemblyLoadContext
|
||||
{
|
||||
private Assembly _pluginAssembly;
|
||||
|
||||
/// <summary>
|
||||
/// 加载程序集
|
||||
/// </summary>
|
||||
/// <param name="pluginPath"></param>
|
||||
public FlowLibraryLoader(string pluginPath) : base(isCollectible: true)
|
||||
{
|
||||
_pluginAssembly = LoadFromAssemblyPath(pluginPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保持默认加载行为
|
||||
/// </summary>
|
||||
/// <param name="assemblyName"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
protected override Assembly Load(AssemblyName assemblyName)
|
||||
{
|
||||
return null; // 保持默认加载行为
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否对程序集的引用
|
||||
/// </summary>
|
||||
public void UnloadPlugin()
|
||||
{
|
||||
_pluginAssembly = null; // 释放对程序集的引用
|
||||
Unload(); // 触发卸载
|
||||
// 强制进行垃圾回收,以便完成卸载
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user