我喜欢在必要时从另一个线程中止HttpWebRequest。这是正确的方法吗?
public void Abort()
{
if (request != null)
{
try { request.ReadWriteTimeout = 0; } catch { }
try { request.Timeout = 0; } catch { }
try { request.Abort(); } catch { }
}
}
答案 0 :(得分:0)
我相信它会为你节省一些努力将一切都放在一个try / catch中。另请看这个:Is it possible to abort a Task like aborting a Thread (Thread.Abort method)?
public void Abort()
{
if (request != null)
{
try
{
request.ReadWriteTimeout = 0; } catch { }
request.Timeout = 0;
request.Abort();
} catch {//Some error}
}
}