PC Review


Reply
Thread Tools Rate Thread

Asynchronous WebClient

 
 
=?Utf-8?B?THVrZQ==?=
Guest
Posts: n/a
 
      28th Nov 2005
I'm trying to automate a process of logging in to a website and posting and
downloading some stuff. I am using asynchronous WebClient methods so the
user can cancel the operation at any time and it's working fine, but I have a
question about the structure of my program. Right now I've got something
like this:

Main()
{
WebClient LoginClient = new ...
// set the relevant properties and eventhandlers
LoginClient.UploadValuesAsync(...);
}

LoginClient_UploadValuesCompleted(...)
{
if(!Cancelled && !Error)
{
WebClient Page1Client = new ...
// set the relevant properties and eventhandlers
Page1Client.DownloadDataAsync(...);
}
}

Page1Client_DownloadDataCompleted(...)
{
if(!Cancelled && !Error)
{
WebClient Page2Client = new ...
// set the relevant properties and eventhandlers
Page2Client.DownloadDataAsync(...);
}
}

etc.

I've got about 5 or 6 pages I need to get and I have to get them in order,
so in each request's completed event handler I start the next request. Is
this the right way to do things? There seems to be a fair amount of repeated
code and it just feels a little strange, but it works fine.

Also, whenever I start the program and start the first request for the first
time it blocks for about a second even though it's started asynchronously.
No other requests block, even if I cancel and restart the request sequence.
If I restart the program, the first request blocks again. Is this just
because some initialization occurs in the background or something? Is there
any way to avoid this?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
buggy asynchronous webClient bill tie Microsoft C# .NET 4 14th Oct 2008 02:43 PM
WebClient Rippo Microsoft ASP .NET 1 14th Jun 2006 06:43 PM
WebClient =?Utf-8?B?Q2hpcmFtYmF0dHU=?= Microsoft Dot NET 2 23rd Sep 2005 01:49 AM
**Webclient and SSL** Ron Microsoft VB .NET 0 19th Aug 2004 06:36 PM
WebClient DownloadFile gets ALL files in directory?!? WebClient bug? Jeremy Microsoft Dot NET Framework 1 10th Nov 2003 01:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:40 PM.