PC Review


Reply
Thread Tools Rate Thread

Destroying ActiveX controls

 
 
Peter Merwood
Guest
Posts: n/a
 
      13th Aug 2004
Hi

My VB.NET project has a Form which wraps a proprietary ActiveX control.
Efffectively the Form acts as a Class becuase the control must be placed on
a Form. The Form is not displayed by the application.

The application instantiates the Form, uses the control to connect to a
backend process disconnects, closes the Form and then performs a garbage
collection. However after four or five cycles of this the control stops
connecting to the backend process. I know the particular control to be
reliable becuase I've used it in VB6 projects without any problem. I
suspect after the Form and control is closed it's not being properly garbage
collected.

At present I've setup the following.

In the Form_Closing event I call the Control's disconnect method and then
the Control.Dispose method.

In the sub that instantiates the Form I've included the following:

If Not (lfrmCTI Is Nothing) Then
lfrmCTI.Close()
lfrmCTI.Dispose()

lfrmCTI = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()

End If

Can someone tell me if this is the correct strategy to use to guarantee that
my Form and the control that it hosts will be detsroyed? Thanks.
--



----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Aug 2004
Peter,

It seems me much to much, when it is a form, it implements Idisposable, that
means that a close should be enough because that does all the work.

I hope this helps?

Cor
>
> If Not (lfrmCTI Is Nothing) Then
> lfrmCTI.Close()
> lfrmCTI.Dispose()
>
> lfrmCTI = Nothing
>
> GC.Collect()
> GC.WaitForPendingFinalizers()
>
> End If
>



 
Reply With Quote
 
Peter Merwood
Guest
Posts: n/a
 
      13th Aug 2004
Cor

I was hoping the Close method would take care of the destruction of the Form
and any controls (ActiveX or otherwise) that it might contain. However, I'm
not so sure about this. I'd appreciate someone telling me whether a call to
Form.Close followed by a GC.Collect is enough.

Peter,

--


----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com

"Cor Ligthert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Peter,
>
> It seems me much to much, when it is a form, it implements Idisposable,

that
> means that a close should be enough because that does all the work.
>
> I hope this helps?
>
> Cor
> >
> > If Not (lfrmCTI Is Nothing) Then
> > lfrmCTI.Close()
> > lfrmCTI.Dispose()
> >
> > lfrmCTI = Nothing
> >
> > GC.Collect()
> > GC.WaitForPendingFinalizers()
> >
> > End If
> >

>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Aug 2004
Peter,

Calling the GC has nothing to do with the destruction.
The GC is to help cleaning up the managed heap.

When you will search this newsgroup or other newsgroups mostly told as
useless.

However there are people who want that there is almost 50% of memory not
used in there computer, those are often calling the GC.

To get more information see this.

http://msdn.microsoft.com/architectu...l/scalenet.asp

This is a very large document. When you read about dispose, think than that
is about classes which do not implement Idisposable. (There will be a new
article about that in future).

Cor


 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      16th Aug 2004
On Fri, 13 Aug 2004 17:41:23 +1200, Peter Merwood wrote:

> Can someone tell me if this is the correct strategy to use to guarantee that
> my Form and the control that it hosts will be detsroyed? Thanks.


I don't know if it will solve your problem, but take a look at the
Marshal.ReleaseCOMObject method. I believe that you need to call this to
release the COM object.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Windows Forms Controls as ActiveX controls =?Utf-8?B?bGFyc2dyZWdlcnNlbg==?= Microsoft Dot NET 2 18th Oct 2007 10:01 AM
activex settings prohibit running ActiveX controls Bob Hartung Windows XP Help 3 21st Jul 2005 05:49 AM
Message box breaks owner draw controls in .NET controls used as ActiveX controls (again) Clive Dixon Microsoft Dot NET Framework Forms 0 26th May 2004 10:15 AM
Printing a worksheet with ActiveX controls messes up the controls Deane Yang Microsoft Excel Discussion 11 29th Mar 2004 05:25 PM
ActiveX controls or custom controls disappaer in the project! Giobibo Microsoft Dot NET 0 30th Jul 2003 09:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:34 AM.