VC++ 2005 .NET and downloads

B

Behold

Hi folks, completely new here and to .NET for that matter.

I have an application I am working on as a learning experience which
downloads a file via HTTP from a web site into whatever directory I
choose. This is not the issue.

The issue(s) is/are that my form WILL NOT show until AFTER the
download is complete for some reason. I don't understand it at all.
If I use this->Visible = true, the form shows, but is frozen and
parts are greyed out.

Second issue is showing progress during the download. I would like to
update a progressbar while the file downloads. Can't figure this out
in VC++ 2005 .NET for some reason, heh. I am SURE I am missing
something fundamentally simple about it. Code snippet below...

Oh, and yes, I start the download when the form starts up. I do this
just for learning purposes, not for an application I plan on
deploying. :)

// Initialize WebClient
WebClient^ myClient = gcnew WebClient();

// Download a file...
myClient->Headers->Add("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT;
5981.XZ34;)");
Stream^ data =
myClient->OpenRead("http://www.mywebsite/downloads/testfile.txt");
StreamReader^ myReader = gcnew StreamReader(data);
String^ s = myReader->ReadToEnd();
myClient->DownloadFile("http://www.mywebsite.com/downloads/testfile.txt",
"testfile.txt");

textBox1->AppendText("Download
finished!\r\n");

data->Close();
myReader->Close();

That is basically what I have right now. I didn't include the
progressbar code attempt I had since I deleted it last night in a fit
of "man, I can't do this!" just before bed. :blush:

Any help on this is very much appreciated.

TIA,
Behold
 
G

Girish Bharadwaj

I think you might want to look into BeginInvoke(). Basically, You might have
to use a ThreadPool to do the download on a different thread while your UI
is responsive.
 

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