Đây là một câu hỏi followup để thisĐó là nhanh hơn - Một Sử dụng chặn hoặc try/catch/Cuối cùng
Tôi có nên gắn bó với try/catch/Cuối cùng xây dựng, hoặc đi với Sử dụng xây dựng?
mẫu mã cho try/catch/Cuối cùng:
Dim oRequest As WebRequest
Dim oResponse As HttpWebResponse = Nothing
Dim dataStream As Stream = Nothing
Dim reader As StreamReader = Nothing
Dim responseFromServer As String
Try
sNewCustomerURL = NewCustomerQueryStringPrepare()
'make the call to the webservice to add a new customer
oRequest = WebRequest.Create(sNewCustomerURL)
oRequest = CType(oRequesC, HttpWebRequest)
oRequest.Method = "GET"
oResponse = CType(oRequest.GetResponse(), HttpWebResponse)
dataStream = oResponse.GetResponseStream()
reader = New StreamReader(dataStream)
responseFromServer = reader.ReadToEnd()
Dim xml As New XmlDocument()
xml.LoadXml(responseFromServer)
Dim node As XmlNodeList = xml.GetElementsByTagName("SUCCESS")
Dim value = CBool(node(0).InnerText)
'do stuff
Catch ex As Exception
'process exception
Finally
'do cleanup
oRequest = Nothing
If Not oResponse Is Nothing Then
oResponse.Close()
End If
oResponse = Nothing
If Not reader Is Nothing Then
reader.Close()
End If
reader = Nothing
If Not dataStream Is Nothing Then
dataStream.Flush()
dataStream.Close()
End If
dataStream = Nothing
End Try
Tôi biết những gì mã sẽ cần phải được cho dùng xây dựng. Tôi chỉ muốn biết nếu sử dụng cấu trúc Sử dụng sẽ nhanh hơn so sánh chu kỳ đồng hồ.
Lệnh 'thẻ using' nhanh hơn nhiều . Đã lưu tôi khoảng 5 giây khi nhập. – tidwall