Backgroundworker issue

U

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
U

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
 

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