使用MEF vb.net.net framework 4.5动态加载dll
我正在使用下面的方法在vb.net中动态加载dll我正在使用LoadPlugins方法使用AggregateCatalog在名为Extensions的目录中查找插件一切正常,我使用下面的第二个列表运行dll,因为您可以看到我在使用下面的类的延迟加载 导入System.ComponentModel.Composition 导入System.ComponentModel.Composition.Hosting 我的问题是如何正确退出dll应用程序?它是否足够简单,可以在dll中使用application.exit,或者在主应用程序结束之前,它是否仍然驻留在内存中 第一个代码列表使用MEF vb.net.net framework 4.5动态加载dll,.net,vb.net,dll,.net,Vb.net,Dll,我正在使用下面的方法在vb.net中动态加载dll我正在使用LoadPlugins方法使用AggregateCatalog在名为Extensions的目录中查找插件一切正常,我使用下面的第二个列表运行dll,因为您可以看到我在使用下面的类的延迟加载 导入System.ComponentModel.Composition 导入System.ComponentModel.Composition.Hosting 我的问题是如何正确退出dll应用程序?它是否足够简单,可以在dll中使用applicati
Private Sub LoadPlugins()
' Add any initialization after the InitializeComponent() call.
'An aggregate catalog that combines multiple catalogs
Dim catalog = New AggregateCatalog()
'Adds all the parts found in the same assembly as the Program class
catalog.Catalogs.Add(New AssemblyCatalog(GetType(frmMainImports).Assembly()))
'IMPORTANT!
'You will need to adjust this line to match your local path!
catalog.Catalogs.Add(New DirectoryCatalog("Extensions"))
'Create the CompositionContainer with the parts in the catalog
_container = New CompositionContainer(catalog)
'Fill the imports of this object
Try
_container.ComposeParts(Me)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub btnRunImport_Click(sender As Object, e As EventArgs) Handles btnRunImport.Click
Try
For Each i As Lazy(Of IImport, IMetaName) In extensions
'Search for matching extension name then invoke MyMethod in that extension then
'set textbox1.text to the return value
If i.Metadata.MyName = lbPlugins.SelectedItem Then txtDescription.Text = i.Value.Import("Hello From")
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
第二个代码列表
Private Sub LoadPlugins()
' Add any initialization after the InitializeComponent() call.
'An aggregate catalog that combines multiple catalogs
Dim catalog = New AggregateCatalog()
'Adds all the parts found in the same assembly as the Program class
catalog.Catalogs.Add(New AssemblyCatalog(GetType(frmMainImports).Assembly()))
'IMPORTANT!
'You will need to adjust this line to match your local path!
catalog.Catalogs.Add(New DirectoryCatalog("Extensions"))
'Create the CompositionContainer with the parts in the catalog
_container = New CompositionContainer(catalog)
'Fill the imports of this object
Try
_container.ComposeParts(Me)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub btnRunImport_Click(sender As Object, e As EventArgs) Handles btnRunImport.Click
Try
For Each i As Lazy(Of IImport, IMetaName) In extensions
'Search for matching extension name then invoke MyMethod in that extension then
'set textbox1.text to the return value
If i.Metadata.MyName = lbPlugins.SelectedItem Then txtDescription.Text = i.Value.Import("Hello From")
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
不太清楚“退出dll应用程序”是什么意思。DLL不是应用程序-它们是库。从DLL中调用Application.Exit将关闭主应用程序。@DeveloperGuo我想问的是,打开DLL后卸载DLL的最佳方法是什么