How to Destroy/Dispose/Release an object which is created by IPersistStreamInit Interface

  • Thread starter Onur Buyukcaglar
  • Start date
O

Onur Buyukcaglar

Hi,
After reading and applying the following sample/example from Charles Law,
who responded Vibhu Bansal's "createDocumentFromUrl usage in VB.NET /
loading a url using mshtml.createDocumentFromUrl " questions, I have
encountered a problem which I was fail to overcome. The problem is when I
multithreaded the example even though I
set all the variables and the threads to nothing, applications threads are
incresing over and over and at a point the whole screen is bloating with all
empty Internet Explorer Windows. I think I was not able to properly release
/ destroy or dispose these objects after I have finished my job with them.
If anyone has any idea about this situation I would really appreciate for
your help.

Thanks in advance,
Onur Buyukcaglar

PS: I feel that I have to implement IUnknown -> Release on
IPersistStreamInit, but I do not know how to do it in VB.NET.


Sample provided by Charles Law about usage of "CreateDocumentFromUrl in
Vb.Net" as follows.


Imports System.Runtime.InteropServices

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersistStreamInit
' IPersist interface
Sub GetClassID(ByRef pClassID As Guid)

<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As Integer
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, ByVal
ByValfClearDirty As Boolean) As Integer
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As Integer
<PreserveSig()> Function InitNew() As Integer

End Interface


#Region " Imports "

Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

#End Region

Module Module1

Dim IID_IHTMLElementRender As Guid = New
Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b")

<MTAThread()> _
Sub Main()

Dim objMSHTML As mshtml.HTMLDocument
Dim objDocument As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit

objMSHTML = New mshtml.HTMLDocument

ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()

objDocument = objMSHTML.createDocumentFromUrl("http://www.msn.com",
String.Empty)

Do Until objDocument.readyState = "complete"
Threading.Thread.Sleep(1)
Loop

MessageBox.Show(objDocument.body.outerHTML)

End Sub

End Module
 

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

Top