473,396 Members | 1,938 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,396 software developers and data experts.

HOWTO: Manage Async Operations

Hello Every,

Today I am exploring async operations. In my scenario, I have a windows
form with a webbrowser control. The exercise reads a starting webpage and
populates a Queue with additional urls. From there I process each URL in
queue until the queue is empty. The problems that I am encountering are:

1. The browser appears to fire the DocumentCompleted and the Navigated
event more than once for the same url.
2. I often recieve an Invalid Operation Exception, though I have try
catches everywhere I have code.

Anyone have any ideas where I might be going wrong?

Here is what I have

The website is a custom site that simply loads data from my database.

The database simply represents a relationship of people (Grandparent,
Parent, Child)
Entity: People

PersonID Int
ParentPersonID Int
PersonName Int

The Website has a single page view.aspx and accepts one of two paramters in
the query.

ParentID or PersonID

the base page will contain a listing of links like so

http:\\localhost\asynctest\view.aspx?parentid=1
http:\\localhost\asynctest\view.aspx?parentid=2
http:\\localhost\asynctest\view.aspx?parentid=3
http:\\localhost\asynctest\view.aspx?parentid=4
http:\\localhost\asynctest\view.aspx?parentid=5

Sub sequent pages will then contain links such as

"Parents"
http:\\localhost\asynctest\view.aspx?parentid=7
http:\\localhost\asynctest\view.aspx?parentid=8

"People"
http:\\localhost\asynctest\view.aspx?personid=10
http:\\localhost\asynctest\view.aspx?personid=11

"Persons"
"Doe, John" <-- Does not get added to the queue

On my winform:

event ProcessingComplete(sender as WebBrowser)

dim theQueue as queue

sub ButtonClick(sender, e)
processsite
end sub

sub Processsite
thequeue = new queue
me.wb.navigate(http:\\localhost\asynctest\view.asp x)
end sub

sub wb_documentcomplete(sender, e)

'This fires multiple times on the same page.

try
'Find all links
<psuedo code>
for each ahref as object in sender.document.getelementsbytagname("A")
thequeue.enqueue(ahref.href)
next
catch ex as exception
'Ignore exception, move on for now
console.writeline(ex.tostring)
end try

try
'Find all persons
<psuedo code>
for each personname as object in
sender.document.getelementsbytagname("STRONG")
console.writeline personname.innterText
next
catch ex as exception
'Ignore exception, move on for now
console.writeline(ex.tostring)
end try

'Inform the UI that this processing is complete
raiseevent processingcomplete(sender)

end sub

sub OnProcessingComplete(sender as WebBrowser) handles ProcessingComplete

try
dim strNewLocation as string
strNewLocation = thequeue.dequeue()
sender.navigate(strNewLocation)
catch ex as exception
'Queue is Empty
msgbox "Job's Done"
exit sub
end try

end sub
Aug 23 '06 #1
0 1102

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

Similar topics

4
by: Bob Badger | last post by:
Hi, Simple question (although I guess with a complicated answer). Is HTTP an async protocol? For instance, if I send a message to a c# webservice via http what is the protocol actually doing? ...
4
by: Roemer | last post by:
Hey all While working with Async Methods and Networking I found something very strange or better a bug? To test it yourself create a new Windows Application with just a Button on the Form. ...
1
by: Chris Mullins | last post by:
We're building high performance database applications, and are trying to use all the new Async ADO.Net 2.0 features. The problem we're having is that we can't find a...
1
by: 1388-2/HB | last post by:
I have a class file in my App_Code folder called "clsBasePage.vb" that looks like this: Public Class clsBasePage Inherits System.Web.UI.Page ...stuff... End Class It's a "page" in that it...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
13
by: Ben Voigt [C++ MVP] | last post by:
This is more of a C# question than a C++ question, but my best chance of explaining it is via comparison to C++. Ok: In C++ you can forward declare a type. Then references to that type can be...
10
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
1
by: robert112 | last post by:
Question... Can one not use ThreadPool.QueueUserWorkItem with an anonymous method like so: ThreadPool.QueueUserWorkItem(delegate { //perform IO bound operation. }); Why did the asp.net team...
3
by: Ryan Liu | last post by:
Hi, Is Async I/O (e.g. NetworkStream.Begin/End Read/Write) always better than synchronous I/O? At least as good? When I don't concern about easy or difficult to write code, should I always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.