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

Backgroundworker issue

Ulf
Hi,

I have some problems with a BackgroundWorker when calling a WebRequest
:

private void bgrdTask_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = WebServerRequest((string[])e.Arguments);
}

the WebServerRequest function simply creates a HttpWebRequest to the
uri specified in the arguments and returns the StatusDescription if it
is successful or the WebException message.

When I use the GetResponse() method, I always end up with a correct
status description, everything is just fine. But when I use the
asynchronous BeginGetResponse() and EndGetResponse() methods, the
AsyncCallback always throws an "Unable to connect to remote server"
WebException. Is there anything special I have to implement to get
BackgroundWorkers working when they have to call themselves
asynchronous functions ?

thx :)

Ulf

Nov 28 '05 #1
2 2892
Ulf,

There shouldn't be any difference. However, I do wonder why you have
both an asynchronous call and the background worker? If you are performing
an asynchronous call, then there is little need for the background worker,
and if you are using a background worker, there is little need for an
asynchronous call.

You should choose one or the other.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ulf" <wa******@aol.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi,

I have some problems with a BackgroundWorker when calling a WebRequest
:

private void bgrdTask_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = WebServerRequest((string[])e.Arguments);
}

the WebServerRequest function simply creates a HttpWebRequest to the
uri specified in the arguments and returns the StatusDescription if it
is successful or the WebException message.

When I use the GetResponse() method, I always end up with a correct
status description, everything is just fine. But when I use the
asynchronous BeginGetResponse() and EndGetResponse() methods, the
AsyncCallback always throws an "Unable to connect to remote server"
WebException. Is there anything special I have to implement to get
BackgroundWorkers working when they have to call themselves
asynchronous functions ?

thx :)

Ulf

Nov 28 '05 #2
Ulf
Hi Nicholas,

thx for your reply. I know it seems strange to use both
backgroundworkers and asynchronous calls, but when creating a
synchronous webrequest with the backgroundworker, I can only invoke the
CancelAsync(), but nor directly abort the request when e.g. a timout
limit has been reached, unless I'm missing something here. I could of
course use all the calls synchronously from the backgroundworker, but
the strange part here is precisely that webrequest (HttpWebRequest
or/and FtpWebRequest) do not behave the same way if used synchronously
or asynchronously. As you noted, there shouldn't be any
difference....yet there is.

Ulf

Nov 29 '05 #3

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

Similar topics

2
by: Matthias S. | last post by:
Hi, I've written a simple app which should just fetch some data from a database and render the results into a ListView. In order to not freeze the GUI, I'm using a BackgroundWorker. The...
8
by: Mitchell Vincent | last post by:
I just read my MSDN magazine from last month and was very pleased to see an article about performance and the small(er) things you can do to improve it. I have a pretty big database driven...
5
by: elziko | last post by:
I know I can stop my thread by using the CancelAsync method of the BackgroundWorker but that requires me to monitor the value of the CancellationPending property in my BackgroundWorker.DoWork...
5
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in...
9
by: =?Utf-8?B?VE9NX1Bhc2FkZW5h?= | last post by:
Hello, In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load function. In that thread I'm attempting to connect to a SQL server using this connection string "Initial...
3
by: ray.ackley | last post by:
Hello all, I have an app that uses a BackgroundWorker() object to read USB data that is being fed in serially (FT245R chip, www.ftdichip.com). It looks just like a serial data stream. Anyhow,...
8
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I have an application with several BackgroundWorker threads. I hoped I'd be able to just type backgroundworker1.Name = "bw1"; but I don't see a name property. Any thoughts on how to name a...
3
by: ercastro | last post by:
I am a new user of Visual Basic. I am currently using VB 2005. I am running a time-consuming task on the built-in BackgroundWorker() control of VB. I am using nested loops and sometimes I need...
7
by: =?Utf-8?B?SGVucnk5OQ==?= | last post by:
What happens here? The backgroundworker (bgw) unzips RTF-Helpfiles (up to 1 MB in size). The ProgressChanged-Event gets the unzipped files (to display them in a RichtTextBox) It follows the...
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.