Visual Studio 项目仍然“陷入困境”当停止时

发布于 2024-08-30 23:19:07 字数 1123 浏览 2 评论 0原文

目前正在开发 HP 质量中心的连接器 DLL。我正在使用他们的(插入解释性的)COM API 来连接到服务器。 VStudio 自动创建 Interop 包装器。

我的解决方案有 2 个项目:DLL 和测试器应用程序 - 本质上是一个带有调用 DLL 中函数的按钮的表单。一切都运行良好 - 我可以创建缺陷、更新它们并删除它们。当我关闭主窗体时,应用程序会很好地停止。

但是,当我调用一个返回所有可用项目列表的函数(以填充组合框)时,如果我关闭主窗体,VStudio 仍然显示该解决方案正在运行,我必须停止它。

我成功地在代码中找到了一个函数,当我调用该函数时,解决方案保持“挂起”状态,如果不这样做,它会很好地关闭。这是对 TDC 对象 get_VisibleProjects 中的属性的调用,该属性返回一个 List(不是 .Net 列表,而是 COM 库中的一种类型) - 我只是对其进行迭代并返回一个正确的列表(我稍后用它来填充组合框):

    public List<string> GetAvailableProjects()
    {
        List<string> projects = new List<string>();
        foreach (string project in this.tdc.get_VisibleProjects(qcDomain))
        {
            projects.Add(project);
        }
        return projects;
    }

我的假设是某些内容会保留在内存中。如果我在 VStudio 之外运行 EXE,它会关闭 - 但谁知道内存中会留下什么?

我的问题是 - 如何摆脱调用此属性返回的任何内容? GC不应该处理这个吗?我需要深入研究指针吗?

我尝试过的事情:

  1. 将列表放入变量中并在函数末尾将其设置为 null
  2. 将析构函数添加到类中并将 tdc 对象清空
  3. 单步执行测试器功能应用程序一直退出,当表单关闭且主功能结束时 - 它关闭,但 VStudio 仍然显示我正在运行。

感谢您的帮助!

Currently developing a connector DLL to HP's Quality Center. I'm using their (insert expelative) COM API to connect to the server. An Interop wrapper gets created automatically by VStudio.

My solution has 2 projects: the DLL and a tester application - essentially a form with buttons that call functions in the DLL. Everything works well - I can create defects, update them and delete them. When I close the main form, the application stops nicely.

But when I call a function that returns a list of all available projects (to fill a combo box), if I close the main form, VStudio still shows the solution as running and I have to stop it.

I've managed to pinpoint a single function in my code that when I call, the solution remains "hung" and if I don't, it closes well. It's a call to a property in the TDC object get_VisibleProjects that returns a List (not the .Net one, but a type in the COM library) - I just iterate over it and return a proper list (that I later use to fill the combo box):

    public List<string> GetAvailableProjects()
    {
        List<string> projects = new List<string>();
        foreach (string project in this.tdc.get_VisibleProjects(qcDomain))
        {
            projects.Add(project);
        }
        return projects;
    }

My assumption is that something gets retained in memory. If I run the EXE outside of VStudio it closes - but who knows what gets left behind in memory?

My question is - how do I get rid of whatever calling this property returns? Shouldn't the GC handle this? Do I need to delve into pointers?

Things I've tried:

  1. getting the list into a variable and setting it to null at the end of the function
  2. Adding a destructor to the class and nulling the tdc object
  3. Stepping through the tester function application all the way out, whne the form closes and the Main function ends - it closes, but VStudio still shows I'm running.

Thanks for your assistance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

场罚期间 2024-09-06 23:19:07

尝试将这两行添加到构建后事件中:

call "$(DevEnvDir)..\Tools\vsvars32.bat"
editbin.exe /NXCOMPAT:NO "$(TargetPath)"

Try to add these 2 lines to post-build event:

call "$(DevEnvDir)..\Tools\vsvars32.bat"
editbin.exe /NXCOMPAT:NO "$(TargetPath)"
心凉 2024-09-06 23:19:07

您是否尝试过在完成后使用 System.Runtime.InteropServices.Marshal.ReleaseComObject 手动释放 List 对象?

Have you tried manually releasing the List object using System.Runtime.InteropServices.Marshal.ReleaseComObject when you are finished with it ?

无所谓啦 2024-09-06 23:19:07

我怀疑有一些悬空的线程。

发生这种情况时,请暂停调试器中的进程并查看仍有哪些线程。

I suspect some dangling threads.

When this happens, pause the process in the debugger and see what threads are still around.

动听の歌 2024-09-06 23:19:07

可能会尝试使用它的 count 和 Item 属性手动迭代列表,而不是使用它的迭代器,例如:

for (int i=1; i <= lst.Count ; ++i)
{
 string projectName = lst.Item(i);
}

可能是迭代器使其保持活动状态,而不是列表对象本身,如果不使用迭代器可能不会有问题。

May be try to iterate the list manually using it's count and Item properties instead of using it's iterator, some thing like:

for (int i=1; i <= lst.Count ; ++i)
{
 string projectName = lst.Item(i);
}

It might be the Iterator that keeps it alive and not the list object itself, if not using an iterator might not have a problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文