471,603 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,603 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 2830
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Matthias S. | last post: by
8 posts views Thread by Mitchell Vincent | last post: by
5 posts views Thread by elziko | last post: by
9 posts views Thread by =?Utf-8?B?VE9NX1Bhc2FkZW5h?= | last post: by
8 posts views Thread by =?Utf-8?B?cmFuZHkxMjAw?= | last post: by
7 posts views Thread by =?Utf-8?B?SGVucnk5OQ==?= | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

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.