473,513 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BackgroundWorkers abd WebBrowsers

I'm a bit of a threading newbie, and have just converted an app from
Threads to BackgroundWorkers to try to get some more life out of the
UI. From reading here and elsewhere, I have a general understanding
of the "don't mess with the UI" rule and why that is.

But, what about the case where your thread fires off an async
operation? In that case, the thread's RunWorkerCompleted event fires
almost immediately. Does this mean you're safe? More specifically,
the thread only starts a WebBrowser.Navigate, the WebBrowser
(eventually) fires a DocumentComplete event, and in response to *that*
event, the UI gets updated. (This is the method I'm using to open ten
web pages at once in a tabbed form, and update a visible counter as
each finishes loading.)

On every machines here, that works just fine. I'm suspecting though,
that it might be behind a "cascade of JIT debug messages" reported by
a user whose machine I'm hoping to access in the next few days. But
where to look - just trying to make substantial use of these
WebBrowser controls has taught me many new ways a pc can die, so I
don't want to rush to judgement.

So the question - does the rule still apply here, meaning that I
should used a timed check to keep the BackgroundWorkers alive until
DocumentComplete fires, then raise an event from the thread? If I am
breaking the rule, am I any more likely to see these "intemittent"
symptoms when I'm really overworking a machine?

If that's not a potential source, I'm still a little confused by the
whole error-handling issue when using BackgroundWorkers. Is this
supposed to be something that can cause runtime errors, or is it just
a nuisance in the IDE? I use a standard try-catch on *every* routine,
it passes the exception to a global sub that will log the error, and
pops up a custom error form if that's enabled. The first time I read
about this, it looked like I *must* remove them from anything that
might be in a calling chain originating from a BackgroundWorker. But,
I just haven't had any problems in the IDE - I forced some errors &
saw just what I normally would, both in and out of the IDE.

OTOH, I do not have any error handling in the DoWork event handler,
and was not using the RunWorkerCompleted event at all. Could this
mean that the JIT messages were just unhandled errors (unhandled even
though they have try-catch, because of this issue) that bubbled up to
DoWork, and had nowhere else to go?

I hope that all makes sense, because it's staring to confuse the heck
out of me. Any breadcrumbs would be greatly appreciated.

MikeB

Jul 26 '08 #1
2 1102
Mike B wrote:
I'm a bit of a threading newbie, and have just converted an app from
Threads to BackgroundWorkers to try to get some more life out of the
UI. From reading here and elsewhere, I have a general understanding
of the "don't mess with the UI" rule and why that is.

But, what about the case where your thread fires off an async
operation?
I wouldn't do that. There is no reason not to call an async method directly from
the UI thread, since it will return almost immediately, and later raise an event
when completed. Nesting that within another thread is asking for issues, it
seems to me.

When you do use a background worker, it should only catch exceptions that the
thread can fix and consume, not ones that need to percolate back up to the UI.
Those should be left alone. They will cause the background worker to end and
raise its completed event, with the fact that there was an exception, and what
the exception was, ready for your completed event handler to process
appropriately within the UI thread.
Jul 26 '08 #2
On Sat, 26 Jul 2008 12:49:57 -0700, "Steve Gerrard"
<my********@comcast.netwrote:
>Mike B wrote:
>I'm a bit of a threading newbie, and have just converted an app from
Threads to BackgroundWorkers to try to get some more life out of the
UI. From reading here and elsewhere, I have a general understanding
of the "don't mess with the UI" rule and why that is.

But, what about the case where your thread fires off an async
operation?

I wouldn't do that. There is no reason not to call an async method directly from
the UI thread, since it will return almost immediately, and later raise an event
when completed. Nesting that within another thread is asking for issues, it
seems to me.

When you do use a background worker, it should only catch exceptions that the
thread can fix and consume, not ones that need to percolate back up to the UI.
Those should be left alone. They will cause the background worker to end and
raise its completed event, with the fact that there was an exception, and what
the exception was, ready for your completed event handler to process
appropriately within the UI thread.
Thanks Steve. That's what I get for doing real work based on
subjective analysis I guess - could have sworn the WebBrowser was less
of a hog when in a thread. But having now stripped all that out, what
should have been intuitively obvious - async is async, doing it twice
improves nothing - is apparently true. The real shock was doing
something I should have done long ago - compared my app's performance
loading x pages to IE7's loading the same ones in a tab group. IE7
takes twice as long and is far less responsive during load, so I guess
I'm ok. :)

MikeB
Jul 27 '08 #3

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

Similar topics

5
22729
by: Peter Reinhardt | last post by:
HI, there must be a difference in handling the window.onunload-Event for the two webbrowsers. I have a window, that shows the uptodate-state of the logged in members. The state (is active / is...
7
2548
by: msdev | last post by:
Hello, I am creating my own webbrowser to learn VB .Net. I am stuck on an issue with regards to dynamically-created controls, in this case tabs on a tabcontrol and webbrowsers created within...
7
19818
by: Jayyde | last post by:
Can anyone point me to a good guide for how to do this or give me some pointers? What I'm basically trying to do is use the Web Browser as a picture box that has a web source for the image, but it...
20
416
by: Asper Faner | last post by:
I seem to always have hard time understaing how this regular expression works, especially how on earth do people bring it up as part of computer programming language. Natural language processing...
2
4743
by: harry | last post by:
I have a function run in a seperate Thread (Thread_A) to the main form. I would like Thread_A to take advantage of multi threading and process data using an additional thread. I tried this...
6
1477
by: MarcuEusebiu | last post by:
Hello, I have a Queue and 2 BackGroundWorkers. How can I set one worker to Peek in Queue and the other one to Dequeue the first element from queue? Thanks
5
1073
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I am developing a new application. Since it is being developed from scratch, I want to implement a lot of threading - especially for my SQL calls. The problem I noticed is that I can't seem to...
1
3613
by: =?Utf-8?B?UGF1bCBIYXRjaGVy?= | last post by:
I have a small program which has a large (~50K) number of objects which need to do work. I create a BackgroundWorker object and fire it off whenever each of the instances needs to do work; this...
0
1033
by: dschu012 | last post by:
If I have multiple WebBrowser controls and want to log onto the same site on multiple accounts is this possible? Right now I create a WebBrowser control in one form and log onto a site. Then I create...
0
7171
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
7547
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...
1
7114
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
7541
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...
1
5098
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...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.