Pregunta

Really not sure what I can do with this but hoping that someone may be able to help

Basically I've developed a system that exchanges information with a desktop accounting system via a com interface

What I've done is added a project reference for the com library to my .net project then in my code I create a new instance

Dim myObject as New AccountingLibraryType

This then allows me access to the visible properties, procedures and functions etc e.g.

myObject.Login("Login details go here")

This part all works fine

My problem starts when I finish working with the instance of my object. No matter what I do I frequently end up with the process still running

When I'm discarding my object I do the following

myObject.Logout 'As per Accounting software developers,  should close process
GC.Collect()
Marshel.ReleaseComObject(myObject) ' Also tried Marshal.FinalReleaseComObject(myObject)
myObject = Nothing

Even after all this the process is still left running in my taskmanager.

I've investigated getting the process by ProgID, but unfortunately the end users will commonly be working in directly in the accounting software I have no way to ensure I get the right process.

As far as I can see there isn't anything available on the com object to identify the process for it. I have found I can get the Attribute Collection, but again don't see anyway to get from that to the correct process

Dim attributes As AttributeCollection
attributes = TypeDescriptor.GetAttributes(GetType(AccountingLibraryType))

So firstly, Is there anything else I could be doing to ensure the process is completely closed down when I'm finished with it

Secondly, is there a better way I can create my object instance where I can get some form of handle for the process, but still have access to the visible properties and methods. I've looked at Process and StartInfo but couldn't really see how to get to the required methods etc

I suspect that there is some issue with the internal garbage collection if the accounting software. I've spoken to them a number of times about this but they are unwilling to do anything about it.

Appreciate the any help

¿Fue útil?

Solución

Here is what your looking for:

Marshal.FinalReleaseComObject(myObject)
myObject = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()

You also have to make sure there are no child COM objects that need to be destroyed - if so destroy them in the reverse order.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top