Question WebBrowser still 'active' when form is closed

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
Hi there

On a dynamic form a WebBrowser control connects to a Media Player on one of our servers.

After the form is closed the audio is still running even though the FormClosed event is handled...

VB.NET:
Private Sub Formclose_click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
        UtilForm1.Controls.Clear()
        UtilForm1.Dispose()

            End Sub

Any ideas?

Thanks
 
Controls.Clear() causes the controls to be removed, but not disposed. Disposing the form (though using Close method would be more natural) will automatically dispose child controls. If this FormClosed handler is for same "UtilForm1" reference you don't need any of those calls.
 
Hi John

Thanks for the reply

The form is a opened via ShowModal, so closing only 'hides' the form - I would have thought that calling Form.Dispose would have sorted the issue, but the whole application has to be closed before the streamed audio shuts off...


And yes - the control was added to Utilform1.
 
ShowModal
ShowDialog you mean, true, but then caller should call Dispose when ShowDialog returns. But as I said, don't remove the controls without disposing them, disposing the form also disposes the controls (when they still belong to form).
 
Back
Top