I’m using thread to download something from internet.
I don’t have any loop inside my thread method. I’m using StreamReader.ReadToEnd() method, so
when my thread is downloading something large I want to stop this thread. Preferably without Thread.Abort() method.
Is it possible to give to GC thread to clean, or to finish this?
I’m using thread to download something from internet. I don’t have any loop inside
Share
Don’t do a
ReadToEnd, instead create a loop and read X chars at a time (or read a line at a time withReadLine). Within the loop check whether anAutoResetEventis set (using.WaitOne(0)), if it is then exit the loop.Set the reset event (using
Set) in your other thread when you want to stop the download.