Killing HttpWebRequest object using Thread.Abort

后端 未结 3 1763
-上瘾入骨i
-上瘾入骨i 2020-12-19 09:20

All, I am trying to cancel two concurrent HttpWebRequests using a method similar to the code below (shown in pseudo-ish C#).

The Main method creates two threads whic

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 09:54

    A ThreadAbortException is highly non-specific. HttpWebRequest already supports a way to cancel the request in a predictable way with the Abort() method. I recommend you use it instead.

    Note that you'll still get a WebException on the thread, designed to tell you that the request got aborted externally. Be prepared to catch it.

提交回复
热议问题