Classes VB6 vs. VB.NET

S

Soren Hyltoft

In VB6 i use a Form and a Class module.

Dim MyClass as New Class1

In Form_Load:
Set MyClass = New Class1

In Form_Unload:
Set MyClass = Nothing

This works in VB6
But in .NET i can not destroy the class.
The class only destroys when i Close the application.
If i use the VB6 to .NET wizard, i get an upgrade note:

UPGRADE_NOTE: Object mycls may not be destroyed until it is garbage
collected. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1029"

So how do i destroy a class in .NET

Thanks
 
P

Paul Clement

¤ In VB6 i use a Form and a Class module.
¤
¤ Dim MyClass as New Class1
¤
¤ In Form_Load:
¤ Set MyClass = New Class1
¤
¤ In Form_Unload:
¤ Set MyClass = Nothing
¤
¤ This works in VB6
¤ But in .NET i can not destroy the class.
¤ The class only destroys when i Close the application.
¤ If i use the VB6 to .NET wizard, i get an upgrade note:
¤
¤ UPGRADE_NOTE: Object mycls may not be destroyed until it is garbage
¤ collected. Click for more:
¤ 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1029"
¤
¤ So how do i destroy a class in .NET

Try using Marshal.ReleaseComObject:

http://msdn.microsoft.com/library/d...servicesmarshalclassreleasecomobjecttopic.asp


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
P

Paul Clement

¤ In VB6 i use a Form and a Class module.
¤
¤ Dim MyClass as New Class1
¤
¤ In Form_Load:
¤ Set MyClass = New Class1
¤
¤ In Form_Unload:
¤ Set MyClass = Nothing
¤
¤ This works in VB6
¤ But in .NET i can not destroy the class.
¤ The class only destroys when i Close the application.
¤ If i use the VB6 to .NET wizard, i get an upgrade note:
¤
¤ UPGRADE_NOTE: Object mycls may not be destroyed until it is garbage
¤ collected. Click for more:
¤ 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1029"
¤
¤ So how do i destroy a class in .NET

Here is an example of how to use Marshal.ReleaseComObject:

http://support.microsoft.com/default.aspx?scid=kb;en-us;306682


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top