COM dll 没有被刷新
我正在与我的 C# 项目中名为 CSCCOM 的自定义 COM 组件进行交互。
我用 IDisposable 包装它,如下所示:
Form1.cs
try {
using (CSCCOMWRAP CSC = new CSCCOMWRAP()) {
CSCCodeList CSCL = new CSCCodeList(CSC);
comboBox1.DataSource = CSCL.List;
Marshal.ReleaseComObject(CSCL);
}
}
catch (COMException ex) { }
CSCCodeList.cs
try {
var cscl = CSC.GetCodes();
for (int i = 1; i <= cscl.Count(); i++) {
object item = i;
var code = cscl.Item(ref item);
List.Add(new CSCCode((string)code.Name, Convert.ToString(code.Code)));
}
}
catch (Exception ex) { );
一旦程序执行,我仍然在 ProcessExplorer 下部窗格的 DLL 视图。
这表明由于某种原因我的 COM dll 没有从系统中清除。
I am interacting with a custom COM component called CSCCOM in my c# project.
I am wrapping it with IDisposable as below:
Form1.cs
try {
using (CSCCOMWRAP CSC = new CSCCOMWRAP()) {
CSCCodeList CSCL = new CSCCodeList(CSC);
comboBox1.DataSource = CSCL.List;
Marshal.ReleaseComObject(CSCL);
}
}
catch (COMException ex) { }
CSCCodeList.cs
try {
var cscl = CSC.GetCodes();
for (int i = 1; i <= cscl.Count(); i++) {
object item = i;
var code = cscl.Item(ref item);
List.Add(new CSCCode((string)code.Name, Convert.ToString(code.Code)));
}
}
catch (Exception ex) { );
Once the program is executed, I still see CSCCOM.dll twice in the ProcessExplorer's lower pane's DLL view.
This suggests that for some reason my COM dll is not getting flushed out of the system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是
CSCCodeList.cs
中需要修改的内容:Here is what needed to be modified in
CSCCodeList.cs
:很长时间没有 COM,但在我看来,您从未
使用 ReleaseComObject 释放 cscl 或代码变量,导致 RCW 计数没有递减并使 dll“浮动”
Long time no COM, but it seems to me you are never releasing the cscl or code vars in
with ReleaseComObject, resulting in RCW counts not being decremented and making the dll "float around"