How can I make my class library STA for use with CreateObject in VBScript? I want to make sure that when i do the following (please see below), the process should terminate/dispose.
Set MyObject = Nothing ' Dispose
Is this possible? I have seen that when i run the above statement, my objects are not disposed and my destructor is not being run. please advise.
Below is a snapshot of my class (which is marked COM visible and is registered for COM Interop):
[Guid("")]
[ClassInterface()]
[ProgID()]
[ComVisible(true)]
public class MyClass {}
Do I need to mark it with another attribute or create another setting for it to be disposed when I set it to nothing from COM?
This has nothing to do with marking your class library STA. .NET doesn’t support deterministic destruction so there is no way have it call anything when you set your reference to Nothing.
The closest construct .NET has is the
IDisposbaleinterface which must be manually called. Like below:Note C# objects do not have desctructors – they have finalizers. The finalizer is run when the object is garbage collected which is some time later than when the object is no longer referenced.