Cannot close my application

Spek

Member
Joined
Nov 6, 2009
Messages
10
Programming Experience
Beginner
Hi,

I'm having troubles with terminating an application. When I close the main form everything dissapears but the process remains active. I think I know the cause, a certain activeX component will not release properly. As soon as I create one, I can't close normally...
VB.NET:
dim someActiveXcomponent = new X()
...
<formClosing>
someActiveXcomponent = nothing

GC.Collect()
GC.WaitForPendingFinalizers  ' here it hangs
Probably a bug in that component, but the problem is that I don't have much of a choice, I'll have to use that component for now. Is there any way to fix this or forcing to close the application anyway?

Regards,
Rick


[EDIT]
Excuse me, I posted to quickly as I already found a solution. Calling
System.Runtime.InteropServices.Marshal.ReleaseComObject( myObject )

will kill the reference and now the application closes properly.

Greetz
 
could put in the form closing event 'end' or 'application.close' or make a quick snippet to end the process. I dont know much about activex so im not too sure.
 
This is the best thing I have found for releasing those pesky COM objects(sometimes they need more than 1 call):
VB.NET:
Private Sub ReleaseObject(ByVal o As Object)
    Dim i As Integer
    If Not o Is Nothing Then
      Try
        i = System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
        While i > 0
          i = System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
        End While
      Catch
      Finally
        o = Nothing
      End Try
    End If
End Sub
:cool:
 
could put in the form closing event 'end' or 'application.close' or make a quick snippet to end the process. I dont know much about activex so im not too sure.
If the form's already closing and thus ending the app, why would you bother putting an End or Application.Exit in at all? Why not just let it close?
 
This happend to me when i had set my application's shutdown mode to "When last form closes", and was caused by 1 form not being closed properly, which kept the app. running.
 
Back
Top