English 中文(简体)
Visual Studio project remains "stuck" when stopped
原标题:

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!

最佳回答

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

call "$(DevEnvDir)..Toolsvsvars32.bat"
editbin.exe /NXCOMPAT:NO "$(TargetPath)"
问题回答

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

I suspect some dangling threads.

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

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.





相关问题
How can i add a button to all windows explorer instances?

I am trying to add a button to one of the existing tool bars in any windows explorer instance. After much research i figured out that BHO (browser helper objects) are the best way to hook to ...

Hunting memory leaks

I m finding leaked heap blocks by using the following command in WinDbg !heap –l With each leaked heap block I get, I m running to following to get the stack trace. !heap -p -a leakedheapblock The ...

Why use CComBSTR instead of just passing a WCHAR*?

I m new to COM. What exactly is the advantage of replacing: L"String" with CComBSTR(L"String") I can see a changelist in the COM part of my .NET application where all strings are replaced in this ...

IThumbnailProvider and IInitializeWithItem

I am trying to develop an IThumbnailProvider for use in Windows 7. Since this particular thumbnail would also be dependant on some other files in the same directory, I need to use something other than ...

Getting a byte array from out of process C++ COM to C#

What s the best way to get a chunk of memory (i.e. void*) from a COM server to C#? We have been using an IStream (using CreateStreamOnHGlobal) and passing that back, which worked. However when we ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

热门标签