Streaming with System.IO and System.Net

  • Thread starter Charles A. Lackman
  • Start date
C

Charles A. Lackman

Hello,

I have an app that has a process bar on it and it sends and retrieves data
back and forth to a web page using WebRequest and WebResponse. The stream
is received from the web page and written into a memorystream then written
to a file on the hard drive. When the app's start button is clicked the
first thing that happens is that the size of the file is displayed (i.e. 51
of 562 Downloaded) untile the download is complete. The problem is that
when you click on the cancel button (to stop the download) or if you click
around the form or outside of the form, the application stops responding,
the cancel buttons event does not fire when the steaming is happening.

Any suggestions will be greatly appreciated.

Chuck
 
G

Guest

Seems like the app crashes when focus is changed.

The focus could remain on the progressbar as I get the impression
there's really nothing the user is supposed to to until the download
is done anyway.

I'd also set a breakpoint on the Cancel button click handler.
There's housekeeping to be done there for sure.
 
S

Scott Emick

Maybe you could launch a seprate process to do the sending and receiving of
the data which would periodically update the ui?

Because your are doing the data retrieval synchronously and therefore cannot
put doevents anywhere to allow the ui to update/check for events.

Scott Emick
 
F

Feroze [msft]

Instead of using sync apis, use the asynchronous versions of
Httpwebrequest/response. Then, in the callback handler, make sure that you
post messages to the main window.

--
feroze

-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.

See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------
 
R

Richard Grimes [MVP]

Feroze said:
Instead of using sync apis, use the asynchronous versions of
Httpwebrequest/response. Then, in the callback handler, make sure
that you post messages to the main window.

....and since this will be a thread pool thread, make sure that all
communications with the GUI window is through ISynchronizeInvoke.Invoke

Richard
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top