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.
 

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

Back
Top