WebClient question

  • Thread starter Thread starter chris.dannemiller
  • Start date Start date
C

chris.dannemiller

I have a connection through WebClient running via a thread. Then I call
a .OpenRead(). I would like the main thread to be able to cancel this
connection. How do I go about it.
 
Your main thread should not cancel the connection. Rather, you should
set a flag somewhere that is checked through each iteration of your routine
which reads from the stream. If the flag is set, then you break out of the
loop.

You should also use the Stream returned from OpenRead in a using
statement, so that you get auto-dispose semantics.

Hope this helps.
 
Back
Top