473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

MSHTML asp.net web application SLOW!

Hi Guys,

I have been reading heaps of information in regards to MSHTML object
being used in .NET applications, windows and UI-less. I have read the
walkall samples and tried various techniques with MSHTML. My biggest
problem seems to be running MSHTML in asp.net application and looping
elements in the document.

Example:

a) Grab site (http://www.amazon.com) into MSHTML htmldocument
b) Loop the element collection ihtmlelementCollection (~1300 elements
for amazon)
c) Accessing properties for each of these nodes such as tagname,
currentstyle.fontsize etc

I have found the following problems:

1) When using Ctype to cast to appropiate types its slower than the
late binding method such as collection(i).tagname

2) Looping 1300 elements takes 5 - 8 seconds ... in the equivalent
VB.NET windows application same code, takes only 0.5 seconds.

The following is the code I use as a sample aspx page:

' ========[ 3 - 4 seconds ]
========================================
Dim htmldocument as New mshtml.htmldocument

Dim doc As mshtml.IHTMLDocument2 =
CType(htmldocument.createDocumentFromUrl(strString , ""),
mshtml.IHTMLDocument2)

Dim timeout As DateTime = Now

Do Until htmldocument.readyState = "complete" Or Now.Subtract
(timeout).TotalSeconds >= 4
System.Threading.Thread.CurrentThread.Sleep(100)
Loop
' ========[ 5 - 8 seconds ]
========================================
Dim mycollection As mshtml.IHTMLElementCollection =
pageDoc.body.all
Dim colLength As Int32 = mycollection.length

Dim result As New StringBuilder("")

Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim e As String
Dim myInnerText As String

For i As Integer = 0 To colLength - 1

a = mycollection.item(i).tagName
b = mycollection.item(i).currentStyle.fontfamily
c = mycollection.item(i).currentStyle.fontSize
d = mycollection.item(i).currentStyle.fontWeight
e = mycollection.item(i).currentStyle.fontStyle

' Get TAG node

myInnerText = CStr(mycollection.item(i).innerHTML)

result.Append(a)
result.Append(" - ")
result.Append(b)
result.Append(" - ")
result.Append(c)
result.Append(" - ")
result.Append(" - ")
result.Append(d)
result.Append(" - ")
result.Append(e)

Next

Any help would be greatly appreciated on how to solve this annoying
problem to speed it up, I have read marshalling is what could be
killing me but what can I do about it?

Regards DotNetShadow
Nov 20 '05 #1
3 2747
Cor
Hi DotNetShadow

When you can use the 2 methods, it is sometimes faster.
I don't know if it works for you but maybe you can give it a try?
Dim mycollection As mshtml.IHTMLElementCollection2 =
pageDoc.body.all


Do you tell us if this was true, I am not sure of this?

Cor
Nov 20 '05 #2
Hi Cor,

What two methods you talking about? I figured out the answer in the
end thanks to igor who suggested that marshalling was killing me ...
so what I did was from the asp.net page spawn a new thread that was
STA since MSHTML is a single-threaded component and that dramatically
improved performance. Although I did encounter this strange problem

Dim doc As mshtml.IHTMLDocument2 =
CType(htmldocument.createDocumentFromUrl(strString , ""),
mshtml.IHTMLDocument2)

seems to fail when in STA model... so I had to use the webrequest
object and write the data into the document object such as:

Dim client As New WebClient

' Add a user agent header in case the
' requested URI contains a query.
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")

Dim data As Stream =
client.OpenRead("http://www.microsoft.com")
Dim reader As New StreamReader(data)
Dim html As String = reader.ReadToEnd()
data.Close()
reader.Close()

Dim doc As New mshtml.HTMLDocument
Dim doc2 As mshtml.IHTMLDocument2 = doc
doc2.open()
doc2.write(html)
doc2.close()

Is there any reason why doing it the original way
htmldocument.createDocumentFromUrl
would cause a NullException error or even have a an empty document
with url as about:blank?

Regards DotNetShadow
"Cor" <no*@non.com> wrote in message news:<#R**************@TK2MSFTNGP12.phx.gbl>...
Hi DotNetShadow

When you can use the 2 methods, it is sometimes faster.
I don't know if it works for you but maybe you can give it a try?
Dim mycollection As mshtml.IHTMLElementCollection2 =
pageDoc.body.all


Do you tell us if this was true, I am not sure of this?

Cor

Nov 20 '05 #3
Cor
Hi DotNetShadow,

I also use the webclient for downloading and those things, it is very fast.

For retrieving the information from the document I also use the mshtml.

With the 2 methods I did want to say, that there are a lot of members like
documents2 and navigate2 and so.

The 2 methods are sometimes a lot faster.

I am happy you solved your problem.

Cor

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Charles Law | last post by:
Sorry for the cross post, but I'm not sure who is best placed to answer this one. This is the most bizarre behaviour of MSHTML and streams. I have a WebBrowser control that contains nothing...
0
by: Erich Hofacker | last post by:
Hello, I have written an application in .NET (C#) which uses some stuff from the Microsoft.mshtml. Unfortunately some customers reported that they are missing this DLL. Therefore we now...
1
by: Oliver | last post by:
hi - my foray into 'autobrowsing' using mshtml etc is going ok - but rather slow (partly) because I'm struggling to find documentation. anyone have any idea how to achieve authentication in an...
1
by: Taylor | last post by:
I was pleased to find this that I could easily access all the links in a page using this construct: IHTMLDocument2 d = (IHTMLDocument2) ie.Document; IHTMLElementCollection links = d.links; ...
2
by: DotNetShadow | last post by:
Hi Guys, I have been reading heaps of information in regards to MSHTML object being used in .NET applications, windows and UI-less. I have read the walkall samples and tried various techniques...
0
by: Atara | last post by:
Our application was build with VS 2003. I have tried to run it on a computer with .Net 2.0 (but without .Net 1.1 , as it should be used) and I got the following error - ...
5
by: miktro | last post by:
I have an VB.Net desktop application where I am hosting a WebBrowser. I need to interact with the events in the browser. I encountered the normal problem of, after adding events the normal click...
0
by: Laurent Lequenne | last post by:
Hello All, I'm currently developing a free windows Scrabble (in french :)) application that uses extensively the WebBrowser class of NET 2.0 for configuration, and data browsing. It works 100%...
5
by: Jason | last post by:
Hi, I'm developing an HTML Editor Control using VB.Net 2003 for an application that used to use the DHTML Editor Control that is no longer supported. Well, it's been fun but I've hit a wall with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.